Change in openvpn[master]: Remove openvpn_snprintf and similar functions
A message that is not in the archive (sent off-list or not yet received): gerrit.1711328743000.I07096977e3b562bcb5d2c6f11673a4175b8e12ac@...2715...
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
to review the following change.
Change subject: Remove openvpn_snprintf and similar functions
......................................................................
Remove openvpn_snprintf and similar functions
Old Microsoft versions did strange behaviour but according to the newly added unit test and
https://stackoverflow.com/questions/7706936/is-snprintf-always-null-terminating
this is now standard conforming and we can use the normal snprintf method.
Microsoft own documentation to swprintf also says you nowadays need to define _CRT_NON_CONFORMING_SWPRINTFS to get to non-standard behaviour.
Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac
---
M src/openvpn/buffer.c
M src/openvpn/buffer.h
M src/openvpn/crypto.c
M src/openvpn/crypto_mbedtls.c
M src/openvpn/dns.c
M src/openvpn/env_set.c
M src/openvpn/error.c
M src/openvpn/init.c
M src/openvpn/manage.c
M src/openvpn/options.c
M src/openvpn/pkcs11.c
M src/openvpn/platform.c
M src/openvpn/plugin.c
M src/openvpn/pool.c
M src/openvpn/proxy.c
M src/openvpn/ps.c
M src/openvpn/route.c
M src/openvpn/run_command.h
M src/openvpn/socket.c
M src/openvpn/socks.c
M src/openvpn/ssl_mbedtls.c
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_openssl.c
M src/openvpn/ssl_verify.c
M src/openvpn/ssl_verify_mbedtls.c
M src/openvpn/ssl_verify_openssl.c
M src/openvpn/tls_crypt.c
M src/openvpn/tun.c
M src/openvpn/win32.c
M src/openvpn/win32.h
M src/openvpn/xkey_helper.c
M src/openvpnserv/common.c
M src/openvpnserv/interactive.c
M src/openvpnserv/service.h
M src/openvpnserv/validate.c
M tests/unit_tests/openvpn/test_buffer.c
M tests/unit_tests/openvpn/test_cryptoapi.c M tests/unit_tests/openvpn/test_pkcs11.c
38 files changed, 258 insertions(+), 331 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/47/547/1
src/openvpn/buffer.c +0 -26
@@ -279,32 +279,6 @@return ret; } - -/* -* This is necessary due to certain buggy implementations of snprintf, -* that don't guarantee null termination for size > 0. -* -* Return false on overflow. -* -* This functionality is duplicated in src/openvpnserv/common.c -* Any modifications here should be done to the other place as well. -*/ - -bool -openvpn_snprintf (char *str,size_t size,const char *format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vsnprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =0 ; - } -return (len >=0 && len < size); -} -/* * write a string to the end of a buffer that was * truncated by buf_printf
src/openvpn/buffer.h +0 -13
@@ -448,19 +448,6 @@*/ bool buf_puts (struct buffer *buf,const char *str); -/* -* Like snprintf but guarantees null termination for size > 0 -*/ -bool openvpn_snprintf(char *str, size_t size, const char *format, ...) -#ifdef __GNUC__ -#if __USE_MINGW_ANSI_STDIO -__attribute__ ((format(gnu_printf, 3, 4))) -#else -__attribute__ ((format(__printf__, 3, 4))) -#endif -#endif -; -/* * remove/add trailing characters
src/openvpn/crypto.c +2 -2
@@ -874,11 +874,11 @@key_direction_state_init (&kds, key_direction); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name);init_key_ctx (&ctx->encrypt, &key2->keys[kds.out_key], kt,OPENVPN_OP_ENCRYPT , log_prefix); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name);init_key_ctx (&ctx->decrypt, &key2->keys[kds.in_key], kt,OPENVPN_OP_DECRYPT , log_prefix);
src/openvpn/crypto_mbedtls.c +5 -5
@@ -128,7 +128,7 @@ {char prefix[256 ]; -if (!openvpn_snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) +if (!snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) {return mbed_log_err (flags, errval, func); }
@@ -239,11 +239,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) {return false; }
@@ -278,11 +278,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----" , name)) {return false; }
src/openvpn/dns.c +2 -2
@@ -349,11 +349,11 @@if (j <0 ) { - name_ok =openvpn_snprintf (name,sizeof (name), format, i); + name_ok =snprintf (name,sizeof (name), format, i); }else { - name_ok =openvpn_snprintf (name,sizeof (name), format, i, j); + name_ok =snprintf (name,sizeof (name), format, i, j); }if (!name_ok)
src/openvpn/env_set.c +4 -4
@@ -259,7 +259,7 @@ setenv_counter(struct env_set *es, const char *name, counter_type value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf), counter_format, value); +snprintf (buf,sizeof (buf), counter_format, value);setenv_str (es, name, buf); }
@@ -267,7 +267,7 @@ setenv_int(struct env_set *es, const char *name, int value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%d" , value); +snprintf (buf,sizeof (buf),"%d" , value);setenv_str (es, name, buf); }
@@ -275,7 +275,7 @@ setenv_long_long(struct env_set *es, const char *name, long long value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value); +snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value);setenv_str (es, name, buf); }
@@ -310,7 +310,7 @@strcpy (tmpname, name);while (NULL !=env_set_get (es, tmpname) && counter <1000 ) { -ASSERT (openvpn_snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); +ASSERT (snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); counter++; }if (counter <1000 )
src/openvpn/error.c +7 -7
@@ -274,14 +274,14 @@if ((flags &M_ERRNO ) && e) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , - m1,openvpn_strerror (e, crt_error, &gc), e); +snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , + m1,openvpn_strerror (e, crt_error, &gc), e);SWAP ; }if (flags &M_OPTERR ) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1); +snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1);SWAP ; }
@@ -321,10 +321,10 @@const struct virtual_output *vo =msg_get_virtual_output ();if (vo) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , - prefix, - prefix_sep, - m1); +snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , + prefix, + prefix_sep, + m1);virtual_output_print (vo, flags, m2); } }
src/openvpn/init.c +1 -1
@@ -359,7 +359,7 @@char *out =malloc (len);check_malloc_return (out); -openvpn_snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); +snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); *remote = out; }else
src/openvpn/manage.c +4 -4
@@ -515,8 +515,8 @@char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); -openvpn_snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes); +snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); +snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes);msg (M_CLIENT ,">BYTECOUNT:%s,%s" , in, out); }
@@ -528,8 +528,8 @@char in[32 ];char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, *bytes_in_total); -openvpn_snprintf (out,sizeof (out), counter_format, *bytes_out_total); +snprintf (in,sizeof (in), counter_format, *bytes_in_total); +snprintf (out,sizeof (out), counter_format, *bytes_out_total);msg (M_CLIENT ,">BYTECOUNT_CLI:%lu,%s,%s" , mdac->cid, in, out); mdac->bytecount_last_update = now; }
src/openvpn/options.c +4 -4
@@ -1427,7 +1427,7 @@for (int i =1 ; i <= opt_max; ++i) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , i); +snprintf (name,sizeof (name),"foreign_option_%d" , i);const char *env_str =env_set_get (es, name);const char *value =strchr (env_str,'=' ) +1 ;
@@ -1482,7 +1482,7 @@while (o->foreign_option_index < opt_max) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--); +snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--);setenv_del (es, name); } }
@@ -5671,8 +5671,8 @@#ifndef ENABLE_SMALL {char script_name[100 ]; -openvpn_snprintf (script_name,sizeof (script_name), -"--%s script" , type); +snprintf (script_name,sizeof (script_name), +"--%s script" , type);if (check_cmd_access (*script, script_name, (in_chroot ? options->chroot_dir :NULL ))) {
src/openvpn/pkcs11.c +3 -3
@@ -201,7 +201,7 @@CLEAR (token_resp); token_resp.defined = false; token_resp.nocache = true; - openvpn_snprintf( + snprintf( token_resp.username, sizeof(token_resp.username), "Please insert %s token",
@@ -245,7 +245,7 @@ASSERT (token!=NULL ); -openvpn_snprintf (prompt,sizeof (prompt),"%s token" , token->label); +snprintf (prompt,sizeof (prompt),"%s token" , token->label); token_pass.defined = false; token_pass.nocache = true;
@@ -719,7 +719,7 @@ id_resp.defined = false; id_resp.nocache = true; -openvpn_snprintf ( +snprintf ( id_resp.username,sizeof (id_resp.username), "Please specify PKCS#11 id to use"
src/openvpn/platform.c +3 -3
@@ -564,9 +564,9 @@ { ++attempts; -if (!openvpn_snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, - prefix, (unsigned long )get_random (), - (unsigned long )get_random ())) +if (!snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, + prefix, (unsigned long )get_random (), + (unsigned long )get_random ())) {msg (M_WARN ,"ERROR: temporary filename too long" );return NULL ;
src/openvpn/plugin.c +2 -2
@@ -260,7 +260,7 @@ {char full[PATH_MAX ]; -openvpn_snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); +snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); p->handle =dlopen (full,RTLD_NOW ); } else
@@ -409,7 +409,7 @@gc_init (&gc); msg_fmt =gc_malloc (ERR_BUF_SIZE , false, &gc); -openvpn_snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format); +snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format);x_msg_va (msg_flags, msg_fmt, arglist);gc_free (&gc);
src/openvpn/pool.c +1 -1
@@ -766,7 +766,7 @@ifconfig_pool_handle h;in_addr_t local, remote;char buf[256 ]; -openvpn_snprintf (buf,sizeof (buf),"common-name-%d" , i); +snprintf (buf,sizeof (buf),"common-name-%d" , i);#ifdef DUP_CN cn =NULL ;#else
src/openvpn/proxy.c +43 -43
180 lines not on this page · raw message
src/openvpn/ps.c +1 -1
@@ -354,7 +354,7 @@ fnlen =strlen (journal_dir) +strlen (t) +2 ; jfn = (char *)malloc (fnlen);check_malloc_return (jfn); -openvpn_snprintf (jfn, fnlen,"%s/%s" , journal_dir, t); +snprintf (jfn, fnlen,"%s/%s" , journal_dir, t);dmsg (D_PS_PROXY_DEBUG ,"PORT SHARE PROXY: client origin %s -> %s" , jfn, f); fd =platform_open (jfn,O_CREAT |O_TRUNC |O_WRONLY ,S_IRUSR |S_IWUSR |S_IRGRP );if (fd !=-1 )
src/openvpn/route.c +3 -3
@@ -1621,11 +1621,11 @@if (rgi) { -openvpn_snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); +snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); }else { -openvpn_snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); +snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); }bool ret =management_android_control (management,"ROUTE" , out); status = ret ?RTA_SUCCESS :RTA_ERROR ;
@@ -2000,7 +2000,7 @@#elif defined (TARGET_ANDROID )char out[64 ]; -openvpn_snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); +snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); status =management_android_control (management,"ROUTE6" , out);
src/openvpn/run_command.h +2 -2
@@ -66,8 +66,8 @@ {char msg[256 ]; -openvpn_snprintf (msg,sizeof (msg), -"WARNING: Failed running command (%s)" , hook); +snprintf (msg,sizeof (msg), +"WARNING: Failed running command (%s)" , hook);return openvpn_execve_check (a, es, flags |S_SCRIPT , msg); }
src/openvpn/socket.c +6 -6
@@ -2982,11 +2982,11 @@case AF_INET :if (flags &SA_IP_PORT ) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); }inet_ntop (AF_INET , &addr->addr.in4.sin_addr, buf,sizeof (buf));
@@ -2994,7 +2994,7 @@if ((flags &SA_IP_PORT ) && addr->addr.in4.sin_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in4.sin_port)); }break ;
@@ -3005,19 +3005,19 @@struct in_addr ia;memcpy (&ia.s_addr, &addr->addr.in6.sin6_addr.s6_addr[12 ],sizeof (ia.s_addr)); -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix);inet_ntop (AF_INET , &ia, buf,sizeof (buf)); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix);inet_ntop (AF_INET6 , &addr->addr.in6.sin6_addr, buf,sizeof (buf)); }setenv_str (es, name_buf, buf);if ((flags &SA_IP_PORT ) && addr->addr.in6.sin6_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in6.sin6_port)); }break ;
src/openvpn/socks.c +2 -2
@@ -109,8 +109,8 @@ "Authentication not possible."); goto cleanup; } -openvpn_snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , (int )strlen (creds.username), - creds.username, (int )strlen (creds.password), creds.password); +snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , (int )strlen (creds.username), + creds.username, (int )strlen (creds.password), creds.password); size =send (sd, to_send,strlen (to_send),MSG_NOSIGNAL );if (size !=strlen (to_send))
src/openvpn/ssl_mbedtls.c +6 -6
@@ -1531,16 +1531,16 @@char s2[256 ]; s1[0 ] = s2[0 ] =0 ; -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s" , - prefix, -mbedtls_ssl_get_version (ks_ssl->ctx), -mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s" , + prefix, +mbedtls_ssl_get_version (ks_ssl->ctx), +mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); cert =mbedtls_ssl_get_peer_cert (ks_ssl->ctx);if (cert !=NULL ) { -openvpn_snprintf (s2,sizeof (s2),", %u bit key" , - (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); +snprintf (s2,sizeof (s2),", %u bit key" , + (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); }msg (D_HANDSHAKE ,"%s%s" , s1, s2);
src/openvpn/ssl_ncp.c +2 -2
@@ -198,8 +198,8 @@size_t newlen =strlen (o->ncp_ciphers) +1 +strlen (ciphername) +1 ;char *ncp_ciphers =gc_malloc (newlen, false, &o->gc); -ASSERT (openvpn_snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, - ciphername)); +ASSERT (snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, + ciphername)); o->ncp_ciphers = ncp_ciphers; }
src/openvpn/ssl_openssl.c +16 -16
@@ -1774,7 +1774,7 @@if (!biofp) {char fn[256 ]; -openvpn_snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); +snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); biofp =fopen (fn,"w" );ASSERT (biofp); biofp_last_open =time (NULL );
@@ -2116,8 +2116,8 @@#endif /* if OPENSSL_VERSION_NUMBER < 0x30000000L */ } -openvpn_snprintf (buf, buflen,"%d bits %s%s" , -EVP_PKEY_bits (pkey), type, curve); +snprintf (buf, buflen,"%d bits %s%s" , +EVP_PKEY_bits (pkey), type, curve); }/**
@@ -2137,12 +2137,12 @@int signature_nid =X509_get_signature_nid (cert);if (signature_nid !=0 ) { -openvpn_snprintf (sig,sizeof (sig),", signature: %s" , -OBJ_nid2sn (signature_nid)); +snprintf (sig,sizeof (sig),", signature: %s" , +OBJ_nid2sn (signature_nid)); } -openvpn_snprintf (buf, buflen,", peer certificate: %s%s" , - pkeybuf, sig); +snprintf (buf, buflen,", peer certificate: %s%s" , + pkeybuf, sig);EVP_PKEY_free (pkey); }
@@ -2160,8 +2160,8 @@char pkeybuf[128 ] = {0 };print_pkey_details (pkey, pkeybuf,sizeof (pkeybuf)); -openvpn_snprintf (buf, buflen,", peer temporary key: %s" , - pkeybuf); +snprintf (buf, buflen,", peer temporary key: %s" , + pkeybuf);EVP_PKEY_free (pkey); }
@@ -2237,8 +2237,8 @@return ; } -openvpn_snprintf (buf, buflen,", peer signing digest/type: %s %s" , - peer_sig, peer_sig_type); +snprintf (buf, buflen,", peer signing digest/type: %s %s" , + peer_sig, peer_sig_type); }
@@ -2261,11 +2261,11 @@ s1[0 ] = s2[0 ] = s3[0 ] = s4[0 ] =0 ; ciph =SSL_get_current_cipher (ks_ssl->ssl); -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , - prefix, -SSL_get_version (ks_ssl->ssl), -SSL_CIPHER_get_version (ciph), -SSL_CIPHER_get_name (ciph)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , + prefix, +SSL_get_version (ks_ssl->ssl), +SSL_CIPHER_get_version (ciph), +SSL_CIPHER_get_name (ciph));X509 *cert =SSL_get_peer_certificate (ks_ssl->ssl);if (cert)
src/openvpn/ssl_verify.c +11 -11
@@ -421,12 +421,12 @@ }/* export subject name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth);setenv_str (es, envname, subject);#if 0 /* export common name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth);setenv_str (es, envname, common_name);#endif
@@ -435,24 +435,24 @@struct buffer sha1 =x509_get_sha1_fingerprint (peer_cert, &gc);struct buffer sha256 =x509_get_sha256_fingerprint (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha1),BLEN (&sha1),0 ,1 ,":" , &gc)); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , - cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , + cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha256),BLEN (&sha256),0 ,1 ,":" , &gc)); }/* export serial number as environmental variable */ serial =backend_x509_get_serial (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth);setenv_str (es, envname, serial);/* export serial number in hex as environmental variable */ serial =backend_x509_get_serial_hex (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth);setenv_str (es, envname, serial);gc_free (&gc);
@@ -569,7 +569,7 @@ goto cleanup; } -if (!openvpn_snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) +if (!snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) {msg (D_HANDSHAKE ,"VERIFY CRL: filename overflow" ); goto cleanup;
@@ -938,9 +938,9 @@if (!check_auth_pending_method (multi->peer_info, pending_method)) {char buf[128 ]; -openvpn_snprintf (buf,sizeof (buf), -"Authentication failed, required pending auth " -"method '%s' not supported" , pending_method); +snprintf (buf,sizeof (buf), +"Authentication failed, required pending auth " +"method '%s' not supported" , pending_method);auth_set_client_reason (multi, buf);msg (M_INFO ,"Client does not supported auth pending method " "'%s'" , pending_method);
src/openvpn/ssl_verify_mbedtls.c +7 -7
@@ -86,8 +86,8 @@char *serial =backend_x509_get_serial (cert, &gc); ret =mbedtls_x509_crt_verify_info (errstr,sizeof (errstr)-1 ,"" , *flags); -if (ret <=0 && !openvpn_snprintf (errstr,sizeof (errstr), -"Could not retrieve error string, flags=%" PRIx32, *flags)) +if (ret <=0 && !snprintf (errstr,sizeof (errstr), +"Could not retrieve error string, flags=%" PRIx32, *flags)) { errstr[0 ] ='\0' ; }
@@ -307,7 +307,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -431,13 +431,13 @@if (0 ==mbedtls_oid_get_attr_short_name (&name->oid, &shortname) ) { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , - cert_depth, shortname); +snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , + cert_depth, shortname); }else { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , - cert_depth); +snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , + cert_depth); }for (i =0 ; i < name->val.len; i++)
src/openvpn/ssl_verify_openssl.c +4 -4
@@ -279,7 +279,7 @@gc_free (&gc);return FAILURE ; } -openvpn_snprintf (common_name, cn_len,"0x%s" , serial); +snprintf (common_name, cn_len,"0x%s" , serial);gc_free (&gc); }else
@@ -454,7 +454,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -597,8 +597,8 @@ name_expand_size =64 +strlen (objbuf); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, - objbuf); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, + objbuf);string_mod (name_expand,CC_PRINT ,CC_CRLF ,'_' );string_mod ((char *)buf,CC_PRINT ,CC_CRLF ,'_' );setenv_str_incr (es, name_expand, (char *)buf);
src/openvpn/tls_crypt.c +2 -2
@@ -574,8 +574,8 @@ }char metadata_type_str[4 ] = {0 };/* Max value: 255 */ -openvpn_snprintf (metadata_type_str,sizeof (metadata_type_str), -"%i" , metadata_type); +snprintf (metadata_type_str,sizeof (metadata_type_str), +"%i" , metadata_type);struct env_set *es =env_set_create (NULL );setenv_str (es,"script_type" ,"tls-crypt-v2-verify" );setenv_str (es,"metadata_type" , metadata_type_str);
src/openvpn/tun.c +34 -34
164 lines not on this page · raw message
src/openvpn/win32.c +5 -20
@@ -885,8 +885,8 @@char force_path[256 ];char *sysroot =get_win_sys_path (); -if (!openvpn_snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , - sysroot, sysroot, sysroot)) +if (!snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , + sysroot, sysroot, sysroot)) {msg (M_WARN ,"env_block: default path truncated to %s" , force_path); }
@@ -1483,26 +1483,11 @@ }bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vswprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =L'\0' ; - } -return (len >=0 && len < size); -} - -bool get_openvpn_reg_value (const WCHAR *key,WCHAR *value,DWORD size) {WCHAR reg_path[256 ];HKEY hkey; -openvpn_swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME ); +swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME );LONG status =RegOpenKeyExW (HKEY_LOCAL_MACHINE , reg_path,0 ,KEY_READ , &hkey);if (status !=ERROR_SUCCESS )
@@ -1528,7 +1513,7 @@/* if we cannot find installation path from the registry, * use Windows directory as a fallback */ -openvpn_swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); +swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); }if ((install_path[wcslen (install_path) -1 ]) ==L'\\' )
@@ -1553,7 +1538,7 @@if (size ==0 ) {WCHAR val[MAX_PATH ] = {0 }; -openvpn_swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value); +swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value);_wputenv_s (ossl_env[i].name, val); } }
src/openvpn/win32.h +0 -8
@@ -319,14 +319,6 @@int openvpn_execve (const struct argv *a,const struct env_set *es,const unsigned int flags); -/* -* openvpn_swprintf() is currently only used by Windows code paths -* and when enabled for all platforms it will currently break older -* OpenBSD versions lacking vswprintf(3) support in their libc. -*/ -bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -/* Sleep that can be interrupted by signals and exit event */ void win32_sleep (const int n);
src/openvpn/xkey_helper.c +5 -5
@@ -205,7 +205,7 @@ }else { -openvpn_snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); } }else if (!strcmp (alg.keytype,"ED448" ) || !strcmp (alg.keytype,"ED25519" ))
@@ -229,8 +229,8 @@/* For undigested message, add hashalg=digest parameter */ else { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , -"RSA_PKCS1_PADDING" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , +"RSA_PKCS1_PADDING" , alg.mdname); } } else if (!strcmp(alg.padmode, "none") && (flags & MF_EXTERNAL_KEY_NOPADDING)
@@ -240,8 +240,8 @@ }else if (!strcmp (alg.padmode,"pss" ) && (flags &MF_EXTERNAL_KEY_PSSPAD )) { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , -"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , +"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); }else {
src/openvpnserv/common.c +10 -40
98 lines not on this page · raw message
src/openvpnserv/interactive.c +27 -27
159 lines not on this page · raw message
src/openvpnserv/service.h +0 -6
@@ -81,12 +81,6 @@ VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv); -BOOL openvpn_vsntprintf (LPTSTR str,size_t size,LPCTSTR format,va_list arglist); - -BOOL openvpn_sntprintf (LPTSTR str,size_t size,LPCTSTR format, ...); - -BOOL openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -DWORD GetOpenvpnSettings (settings_t *s);BOOL ReportStatusToSCMgr (SERVICE_STATUS_HANDLE service,SERVICE_STATUS *status);
src/openvpnserv/validate.c +1 -1
@@ -68,7 +68,7 @@/* convert fname to full path */ if (PathIsRelativeW (fname) ) { -openvpn_swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); +swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); config_file = tmp; }else
tests/unit_tests/openvpn/test_buffer.c +25 -0
@@ -354,6 +354,30 @@assert_string_equal (buf,"There is a .'nice.' \"1234\" [.] year old .tree!" ); } +static void +test_snprintf (void **state) +{ +/* we used to have a custom openvpn_snprintf function because some +* OS (the comment did not specify which) did not always put the +* null byte there. So we unit test this to be sure. +* +* This probably refers to the MSVC behaviour, see also +* https://stackoverflow.com/questions/7706936/is-snprintf-always-null-terminating +*/ + +char buf[10 ] = {'a' }; +assert_int_equal (snprintf (buf,sizeof (buf),"0123456789abcde" ),15 ); +assert_int_equal (buf[9 ],'\0' ); + +memset (buf,'b' ,sizeof (buf)); +assert_int_equal (snprintf (buf,sizeof (buf),"- %d - %d -" ,77 ,88 ),11 ); +assert_int_equal (buf[9 ],'\0' ); + +memset (buf,'c' ,sizeof (buf)); +assert_int_equal (snprintf (buf,sizeof (buf),"- %8.2f" ,77.8899 ),10 ); +assert_int_equal (buf[9 ],'\0' ); +} +int main (void ) {
@@ -387,6 +411,7 @@cmocka_unit_test (test_buffer_free_gc_two),cmocka_unit_test (test_buffer_gc_realloc),cmocka_unit_test (test_character_class), + cmocka_unit_test(test_snprintf) };return cmocka_run_group_tests_name ("buffer" , tests,NULL ,NULL );
tests/unit_tests/openvpn/test_cryptoapi.c +5 -5
@@ -271,7 +271,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); ctx =find_certificate_in_store (select_string, user_store);if (ctx) {
@@ -304,7 +304,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); +snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the common name. But the returned cert may not exactly match
@@ -337,7 +337,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); +snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the issuer. But the returned cert may not exactly match
@@ -411,7 +411,7 @@ {continue ; } -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (Load_CryptoAPI_certificate (select_string, &x509, &privkey) !=1 ) {fail_msg ("Load_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
@@ -446,7 +446,7 @@SSL_CTX *ssl_ctx =SSL_CTX_new_ex (tls_libctx,NULL ,SSLv23_client_method ());assert_non_null (ssl_ctx); -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (!SSL_CTX_use_CryptoAPI_certificate (ssl_ctx, select_string)) {fail_msg ("SSL_CTX_use_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
tests/unit_tests/openvpn/test_pkcs11.c +3 -3
@@ -161,7 +161,7 @@ }else if (flags &GET_USER_PASS_PASSWORD_ONLY ) { -openvpn_snprintf (up->password,sizeof (up->password),"%s" ,PIN ); +snprintf (up->password,sizeof (up->password),"%s" ,PIN ); }else {
@@ -204,8 +204,8 @@ {fail_msg ("make tmpfile using template <%s> failed (error = %d)" , softhsm2_conf_path, errno); } -openvpn_snprintf (config,sizeof (config),"directories.tokendir=%s/" , - softhsm2_tokens_path); +snprintf (config,sizeof (config),"directories.tokendir=%s/" , + softhsm2_tokens_path);assert_int_equal (write (fd, config,strlen (config)),strlen (config));close (fd);
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac
Gerrit-Change-Number: 547
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange
Attention is currently required from: flichtenheld, plaisthos.
ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/547?usp=email )
Change subject: Remove openvpn_snprintf and similar functions
......................................................................
Patch Set 1: Code-Review+2
(1 comment)
Patchset:
PS1:
as far as I understand we can't restore the broken behavior unless we specify that macro or we switch to __snprintf. Both can't happen accidentally, therefore it's not possible introduce the buggy behavior by mistake. In the worst case the code won't compile on old MS systems (pre-VS2015/VC14).
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac
Gerrit-Change-Number: 547
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 25 Mar 2024 01:15:22 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
PATCH 1/1 Remove openvpn_snprintf and similar functions
In reply to a message not in the archiveFrom: Arne Schwabe <[email protected]...>
Old Microsoft versions did strange behaviour but according to the newly added unit test and
https://stackoverflow.com/questions/7706936/is-snprintf-always-null-terminating
this is now standard conforming and we can use the normal snprintf method.
Microsoft own documentation to swprintf also says you nowadays need to define _CRT_NON_CONFORMING_SWPRINTFS to get to non-standard behaviour.
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/547
This mail reflects revision 1 of this Change.
Signed-off-by line for the author was added as per our policy.
Acked-by according to Gerrit (reflected above):
Antonio Quartulli <[email protected]...>
src/openvpn/buffer.c +0 -26
@@ -279,32 +279,6 @@return ret; } - -/* -* This is necessary due to certain buggy implementations of snprintf, -* that don't guarantee null termination for size > 0. -* -* Return false on overflow. -* -* This functionality is duplicated in src/openvpnserv/common.c -* Any modifications here should be done to the other place as well. -*/ - -bool -openvpn_snprintf (char *str,size_t size,const char *format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vsnprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =0 ; - } -return (len >=0 && len < size); -} -/* * write a string to the end of a buffer that was * truncated by buf_printf
src/openvpn/buffer.h +0 -13
@@ -448,19 +448,6 @@*/ bool buf_puts (struct buffer *buf,const char *str); -/* -* Like snprintf but guarantees null termination for size > 0 -*/ -bool openvpn_snprintf(char *str, size_t size, const char *format, ...) -#ifdef __GNUC__ -#if __USE_MINGW_ANSI_STDIO -__attribute__ ((format(gnu_printf, 3, 4))) -#else -__attribute__ ((format(__printf__, 3, 4))) -#endif -#endif -; -/* * remove/add trailing characters
src/openvpn/crypto.c +2 -2
@@ -874,11 +874,11 @@key_direction_state_init (&kds, key_direction); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name);init_key_ctx (&ctx->encrypt, &key2->keys[kds.out_key], kt,OPENVPN_OP_ENCRYPT , log_prefix); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name);init_key_ctx (&ctx->decrypt, &key2->keys[kds.in_key], kt,OPENVPN_OP_DECRYPT , log_prefix);
src/openvpn/crypto_mbedtls.c +5 -5
@@ -128,7 +128,7 @@ {char prefix[256 ]; -if (!openvpn_snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) +if (!snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) {return mbed_log_err (flags, errval, func); }
@@ -239,11 +239,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) {return false; }
@@ -278,11 +278,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----" , name)) {return false; }
src/openvpn/dns.c +2 -2
@@ -349,11 +349,11 @@if (j <0 ) { - name_ok =openvpn_snprintf (name,sizeof (name), format, i); + name_ok =snprintf (name,sizeof (name), format, i); }else { - name_ok =openvpn_snprintf (name,sizeof (name), format, i, j); + name_ok =snprintf (name,sizeof (name), format, i, j); }if (!name_ok)
src/openvpn/env_set.c +4 -4
@@ -259,7 +259,7 @@ setenv_counter(struct env_set *es, const char *name, counter_type value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf), counter_format, value); +snprintf (buf,sizeof (buf), counter_format, value);setenv_str (es, name, buf); }
@@ -267,7 +267,7 @@ setenv_int(struct env_set *es, const char *name, int value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%d" , value); +snprintf (buf,sizeof (buf),"%d" , value);setenv_str (es, name, buf); }
@@ -275,7 +275,7 @@ setenv_long_long(struct env_set *es, const char *name, long long value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value); +snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value);setenv_str (es, name, buf); }
@@ -310,7 +310,7 @@strcpy (tmpname, name);while (NULL !=env_set_get (es, tmpname) && counter <1000 ) { -ASSERT (openvpn_snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); +ASSERT (snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); counter++; }if (counter <1000 )
src/openvpn/error.c +7 -7
@@ -274,14 +274,14 @@if ((flags &M_ERRNO ) && e) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , - m1,openvpn_strerror (e, crt_error, &gc), e); +snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , + m1,openvpn_strerror (e, crt_error, &gc), e);SWAP ; }if (flags &M_OPTERR ) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1); +snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1);SWAP ; }
@@ -321,10 +321,10 @@const struct virtual_output *vo =msg_get_virtual_output ();if (vo) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , - prefix, - prefix_sep, - m1); +snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , + prefix, + prefix_sep, + m1);virtual_output_print (vo, flags, m2); } }
src/openvpn/init.c +1 -1
@@ -359,7 +359,7 @@char *out =malloc (len);check_malloc_return (out); -openvpn_snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); +snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); *remote = out; }else
src/openvpn/manage.c +4 -4
@@ -515,8 +515,8 @@char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); -openvpn_snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes); +snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); +snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes);msg (M_CLIENT ,">BYTECOUNT:%s,%s" , in, out); }
@@ -528,8 +528,8 @@char in[32 ];char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, *bytes_in_total); -openvpn_snprintf (out,sizeof (out), counter_format, *bytes_out_total); +snprintf (in,sizeof (in), counter_format, *bytes_in_total); +snprintf (out,sizeof (out), counter_format, *bytes_out_total);msg (M_CLIENT ,">BYTECOUNT_CLI:%lu,%s,%s" , mdac->cid, in, out); mdac->bytecount_last_update = now; }
src/openvpn/options.c +4 -4
@@ -1427,7 +1427,7 @@for (int i =1 ; i <= opt_max; ++i) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , i); +snprintf (name,sizeof (name),"foreign_option_%d" , i);const char *env_str =env_set_get (es, name);const char *value =strchr (env_str,'=' ) +1 ;
@@ -1482,7 +1482,7 @@while (o->foreign_option_index < opt_max) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--); +snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--);setenv_del (es, name); } }
@@ -5671,8 +5671,8 @@#ifndef ENABLE_SMALL {char script_name[100 ]; -openvpn_snprintf (script_name,sizeof (script_name), -"--%s script" , type); +snprintf (script_name,sizeof (script_name), +"--%s script" , type);if (check_cmd_access (*script, script_name, (in_chroot ? options->chroot_dir :NULL ))) {
src/openvpn/pkcs11.c +3 -3
@@ -201,7 +201,7 @@CLEAR (token_resp); token_resp.defined = false; token_resp.nocache = true; - openvpn_snprintf( + snprintf( token_resp.username, sizeof(token_resp.username), "Please insert %s token",
@@ -245,7 +245,7 @@ASSERT (token!=NULL ); -openvpn_snprintf (prompt,sizeof (prompt),"%s token" , token->label); +snprintf (prompt,sizeof (prompt),"%s token" , token->label); token_pass.defined = false; token_pass.nocache = true;
@@ -719,7 +719,7 @@ id_resp.defined = false; id_resp.nocache = true; -openvpn_snprintf ( +snprintf ( id_resp.username,sizeof (id_resp.username), "Please specify PKCS#11 id to use"
src/openvpn/platform.c +3 -3
@@ -564,9 +564,9 @@ { ++attempts; -if (!openvpn_snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, - prefix, (unsigned long )get_random (), - (unsigned long )get_random ())) +if (!snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, + prefix, (unsigned long )get_random (), + (unsigned long )get_random ())) {msg (M_WARN ,"ERROR: temporary filename too long" );return NULL ;
src/openvpn/plugin.c +2 -2
@@ -260,7 +260,7 @@ {char full[PATH_MAX ]; -openvpn_snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); +snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); p->handle =dlopen (full,RTLD_NOW ); } else
@@ -409,7 +409,7 @@gc_init (&gc); msg_fmt =gc_malloc (ERR_BUF_SIZE , false, &gc); -openvpn_snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format); +snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format);x_msg_va (msg_flags, msg_fmt, arglist);gc_free (&gc);
src/openvpn/pool.c +1 -1
@@ -766,7 +766,7 @@ifconfig_pool_handle h;in_addr_t local, remote;char buf[256 ]; -openvpn_snprintf (buf,sizeof (buf),"common-name-%d" , i); +snprintf (buf,sizeof (buf),"common-name-%d" , i);#ifdef DUP_CN cn =NULL ;#else
src/openvpn/proxy.c +43 -43
180 lines not on this page · raw message
src/openvpn/ps.c +1 -1
@@ -354,7 +354,7 @@ fnlen =strlen (journal_dir) +strlen (t) +2 ; jfn = (char *)malloc (fnlen);check_malloc_return (jfn); -openvpn_snprintf (jfn, fnlen,"%s/%s" , journal_dir, t); +snprintf (jfn, fnlen,"%s/%s" , journal_dir, t);dmsg (D_PS_PROXY_DEBUG ,"PORT SHARE PROXY: client origin %s -> %s" , jfn, f); fd =platform_open (jfn,O_CREAT |O_TRUNC |O_WRONLY ,S_IRUSR |S_IWUSR |S_IRGRP );if (fd !=-1 )
src/openvpn/route.c +3 -3
@@ -1621,11 +1621,11 @@if (rgi) { -openvpn_snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); +snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); }else { -openvpn_snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); +snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); }bool ret =management_android_control (management,"ROUTE" , out); status = ret ?RTA_SUCCESS :RTA_ERROR ;
@@ -2000,7 +2000,7 @@#elif defined (TARGET_ANDROID )char out[64 ]; -openvpn_snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); +snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); status =management_android_control (management,"ROUTE6" , out);
src/openvpn/run_command.h +2 -2
@@ -66,8 +66,8 @@ {char msg[256 ]; -openvpn_snprintf (msg,sizeof (msg), -"WARNING: Failed running command (%s)" , hook); +snprintf (msg,sizeof (msg), +"WARNING: Failed running command (%s)" , hook);return openvpn_execve_check (a, es, flags |S_SCRIPT , msg); }
src/openvpn/socket.c +6 -6
@@ -2982,11 +2982,11 @@case AF_INET :if (flags &SA_IP_PORT ) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); }inet_ntop (AF_INET , &addr->addr.in4.sin_addr, buf,sizeof (buf));
@@ -2994,7 +2994,7 @@if ((flags &SA_IP_PORT ) && addr->addr.in4.sin_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in4.sin_port)); }break ;
@@ -3005,19 +3005,19 @@struct in_addr ia;memcpy (&ia.s_addr, &addr->addr.in6.sin6_addr.s6_addr[12 ],sizeof (ia.s_addr)); -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix);inet_ntop (AF_INET , &ia, buf,sizeof (buf)); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix);inet_ntop (AF_INET6 , &addr->addr.in6.sin6_addr, buf,sizeof (buf)); }setenv_str (es, name_buf, buf);if ((flags &SA_IP_PORT ) && addr->addr.in6.sin6_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in6.sin6_port)); }break ;
src/openvpn/socks.c +2 -2
@@ -109,8 +109,8 @@ "Authentication not possible."); goto cleanup; } -openvpn_snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , (int )strlen (creds.username), - creds.username, (int )strlen (creds.password), creds.password); +snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , (int )strlen (creds.username), + creds.username, (int )strlen (creds.password), creds.password); size =send (sd, to_send,strlen (to_send),MSG_NOSIGNAL );if (size !=strlen (to_send))
src/openvpn/ssl_mbedtls.c +6 -6
@@ -1531,16 +1531,16 @@char s2[256 ]; s1[0 ] = s2[0 ] =0 ; -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s" , - prefix, -mbedtls_ssl_get_version (ks_ssl->ctx), -mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s" , + prefix, +mbedtls_ssl_get_version (ks_ssl->ctx), +mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); cert =mbedtls_ssl_get_peer_cert (ks_ssl->ctx);if (cert !=NULL ) { -openvpn_snprintf (s2,sizeof (s2),", %u bit key" , - (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); +snprintf (s2,sizeof (s2),", %u bit key" , + (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); }msg (D_HANDSHAKE ,"%s%s" , s1, s2);
src/openvpn/ssl_ncp.c +2 -2
@@ -198,8 +198,8 @@size_t newlen =strlen (o->ncp_ciphers) +1 +strlen (ciphername) +1 ;char *ncp_ciphers =gc_malloc (newlen, false, &o->gc); -ASSERT (openvpn_snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, - ciphername)); +ASSERT (snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, + ciphername)); o->ncp_ciphers = ncp_ciphers; }
src/openvpn/ssl_openssl.c +16 -16
@@ -1774,7 +1774,7 @@if (!biofp) {char fn[256 ]; -openvpn_snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); +snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); biofp =fopen (fn,"w" );ASSERT (biofp); biofp_last_open =time (NULL );
@@ -2116,8 +2116,8 @@#endif /* if OPENSSL_VERSION_NUMBER < 0x30000000L */ } -openvpn_snprintf (buf, buflen,"%d bits %s%s" , -EVP_PKEY_bits (pkey), type, curve); +snprintf (buf, buflen,"%d bits %s%s" , +EVP_PKEY_bits (pkey), type, curve); }/**
@@ -2137,12 +2137,12 @@int signature_nid =X509_get_signature_nid (cert);if (signature_nid !=0 ) { -openvpn_snprintf (sig,sizeof (sig),", signature: %s" , -OBJ_nid2sn (signature_nid)); +snprintf (sig,sizeof (sig),", signature: %s" , +OBJ_nid2sn (signature_nid)); } -openvpn_snprintf (buf, buflen,", peer certificate: %s%s" , - pkeybuf, sig); +snprintf (buf, buflen,", peer certificate: %s%s" , + pkeybuf, sig);EVP_PKEY_free (pkey); }
@@ -2160,8 +2160,8 @@char pkeybuf[128 ] = {0 };print_pkey_details (pkey, pkeybuf,sizeof (pkeybuf)); -openvpn_snprintf (buf, buflen,", peer temporary key: %s" , - pkeybuf); +snprintf (buf, buflen,", peer temporary key: %s" , + pkeybuf);EVP_PKEY_free (pkey); }
@@ -2237,8 +2237,8 @@return ; } -openvpn_snprintf (buf, buflen,", peer signing digest/type: %s %s" , - peer_sig, peer_sig_type); +snprintf (buf, buflen,", peer signing digest/type: %s %s" , + peer_sig, peer_sig_type); }
@@ -2261,11 +2261,11 @@ s1[0 ] = s2[0 ] = s3[0 ] = s4[0 ] =0 ; ciph =SSL_get_current_cipher (ks_ssl->ssl); -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , - prefix, -SSL_get_version (ks_ssl->ssl), -SSL_CIPHER_get_version (ciph), -SSL_CIPHER_get_name (ciph)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , + prefix, +SSL_get_version (ks_ssl->ssl), +SSL_CIPHER_get_version (ciph), +SSL_CIPHER_get_name (ciph));X509 *cert =SSL_get_peer_certificate (ks_ssl->ssl);if (cert)
src/openvpn/ssl_verify.c +11 -11
@@ -421,12 +421,12 @@ }/* export subject name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth);setenv_str (es, envname, subject);#if 0 /* export common name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth);setenv_str (es, envname, common_name);#endif
@@ -435,24 +435,24 @@struct buffer sha1 =x509_get_sha1_fingerprint (peer_cert, &gc);struct buffer sha256 =x509_get_sha256_fingerprint (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha1),BLEN (&sha1),0 ,1 ,":" , &gc)); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , - cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , + cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha256),BLEN (&sha256),0 ,1 ,":" , &gc)); }/* export serial number as environmental variable */ serial =backend_x509_get_serial (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth);setenv_str (es, envname, serial);/* export serial number in hex as environmental variable */ serial =backend_x509_get_serial_hex (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth);setenv_str (es, envname, serial);gc_free (&gc);
@@ -569,7 +569,7 @@ goto cleanup; } -if (!openvpn_snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) +if (!snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) {msg (D_HANDSHAKE ,"VERIFY CRL: filename overflow" ); goto cleanup;
@@ -938,9 +938,9 @@if (!check_auth_pending_method (multi->peer_info, pending_method)) {char buf[128 ]; -openvpn_snprintf (buf,sizeof (buf), -"Authentication failed, required pending auth " -"method '%s' not supported" , pending_method); +snprintf (buf,sizeof (buf), +"Authentication failed, required pending auth " +"method '%s' not supported" , pending_method);auth_set_client_reason (multi, buf);msg (M_INFO ,"Client does not supported auth pending method " "'%s'" , pending_method);
src/openvpn/ssl_verify_mbedtls.c +7 -7
@@ -86,8 +86,8 @@char *serial =backend_x509_get_serial (cert, &gc); ret =mbedtls_x509_crt_verify_info (errstr,sizeof (errstr)-1 ,"" , *flags); -if (ret <=0 && !openvpn_snprintf (errstr,sizeof (errstr), -"Could not retrieve error string, flags=%" PRIx32, *flags)) +if (ret <=0 && !snprintf (errstr,sizeof (errstr), +"Could not retrieve error string, flags=%" PRIx32, *flags)) { errstr[0 ] ='\0' ; }
@@ -307,7 +307,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -431,13 +431,13 @@if (0 ==mbedtls_oid_get_attr_short_name (&name->oid, &shortname) ) { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , - cert_depth, shortname); +snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , + cert_depth, shortname); }else { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , - cert_depth); +snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , + cert_depth); }for (i =0 ; i < name->val.len; i++)
src/openvpn/ssl_verify_openssl.c +4 -4
@@ -279,7 +279,7 @@gc_free (&gc);return FAILURE ; } -openvpn_snprintf (common_name, cn_len,"0x%s" , serial); +snprintf (common_name, cn_len,"0x%s" , serial);gc_free (&gc); }else
@@ -454,7 +454,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -597,8 +597,8 @@ name_expand_size =64 +strlen (objbuf); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, - objbuf); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, + objbuf);string_mod (name_expand,CC_PRINT ,CC_CRLF ,'_' );string_mod ((char *)buf,CC_PRINT ,CC_CRLF ,'_' );setenv_str_incr (es, name_expand, (char *)buf);
src/openvpn/tls_crypt.c +2 -2
@@ -574,8 +574,8 @@ }char metadata_type_str[4 ] = {0 };/* Max value: 255 */ -openvpn_snprintf (metadata_type_str,sizeof (metadata_type_str), -"%i" , metadata_type); +snprintf (metadata_type_str,sizeof (metadata_type_str), +"%i" , metadata_type);struct env_set *es =env_set_create (NULL );setenv_str (es,"script_type" ,"tls-crypt-v2-verify" );setenv_str (es,"metadata_type" , metadata_type_str);
src/openvpn/tun.c +34 -34
164 lines not on this page · raw message
src/openvpn/win32.c +5 -20
@@ -885,8 +885,8 @@char force_path[256 ];char *sysroot =get_win_sys_path (); -if (!openvpn_snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , - sysroot, sysroot, sysroot)) +if (!snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , + sysroot, sysroot, sysroot)) {msg (M_WARN ,"env_block: default path truncated to %s" , force_path); }
@@ -1483,26 +1483,11 @@ }bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vswprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =L'\0' ; - } -return (len >=0 && len < size); -} - -bool get_openvpn_reg_value (const WCHAR *key,WCHAR *value,DWORD size) {WCHAR reg_path[256 ];HKEY hkey; -openvpn_swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME ); +swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME );LONG status =RegOpenKeyExW (HKEY_LOCAL_MACHINE , reg_path,0 ,KEY_READ , &hkey);if (status !=ERROR_SUCCESS )
@@ -1528,7 +1513,7 @@/* if we cannot find installation path from the registry, * use Windows directory as a fallback */ -openvpn_swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); +swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); }if ((install_path[wcslen (install_path) -1 ]) ==L'\\' )
@@ -1553,7 +1538,7 @@if (size ==0 ) {WCHAR val[MAX_PATH ] = {0 }; -openvpn_swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value); +swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value);_wputenv_s (ossl_env[i].name, val); } }
src/openvpn/win32.h +0 -8
@@ -319,14 +319,6 @@int openvpn_execve (const struct argv *a,const struct env_set *es,const unsigned int flags); -/* -* openvpn_swprintf() is currently only used by Windows code paths -* and when enabled for all platforms it will currently break older -* OpenBSD versions lacking vswprintf(3) support in their libc. -*/ -bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -/* Sleep that can be interrupted by signals and exit event */ void win32_sleep (const int n);
src/openvpn/xkey_helper.c +5 -5
@@ -205,7 +205,7 @@ }else { -openvpn_snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); } }else if (!strcmp (alg.keytype,"ED448" ) || !strcmp (alg.keytype,"ED25519" ))
@@ -229,8 +229,8 @@/* For undigested message, add hashalg=digest parameter */ else { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , -"RSA_PKCS1_PADDING" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , +"RSA_PKCS1_PADDING" , alg.mdname); } } else if (!strcmp(alg.padmode, "none") && (flags & MF_EXTERNAL_KEY_NOPADDING)
@@ -240,8 +240,8 @@ }else if (!strcmp (alg.padmode,"pss" ) && (flags &MF_EXTERNAL_KEY_PSSPAD )) { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , -"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , +"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); }else {
src/openvpnserv/common.c +10 -40
98 lines not on this page · raw message
src/openvpnserv/interactive.c +27 -27
159 lines not on this page · raw message
src/openvpnserv/service.h +0 -6
@@ -81,12 +81,6 @@ VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv); -BOOL openvpn_vsntprintf (LPTSTR str,size_t size,LPCTSTR format,va_list arglist); - -BOOL openvpn_sntprintf (LPTSTR str,size_t size,LPCTSTR format, ...); - -BOOL openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -DWORD GetOpenvpnSettings (settings_t *s);BOOL ReportStatusToSCMgr (SERVICE_STATUS_HANDLE service,SERVICE_STATUS *status);
src/openvpnserv/validate.c +1 -1
@@ -68,7 +68,7 @@/* convert fname to full path */ if (PathIsRelativeW (fname) ) { -openvpn_swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); +swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); config_file = tmp; }else
tests/unit_tests/openvpn/test_buffer.c +25 -0
@@ -354,6 +354,30 @@assert_string_equal (buf,"There is a .'nice.' \"1234\" [.] year old .tree!" ); } +static void +test_snprintf (void **state) +{ +/* we used to have a custom openvpn_snprintf function because some +* OS (the comment did not specify which) did not always put the +* null byte there. So we unit test this to be sure. +* +* This probably refers to the MSVC behaviour, see also +* https://stackoverflow.com/questions/7706936/is-snprintf-always-null-terminating +*/ + +char buf[10 ] = {'a' }; +assert_int_equal (snprintf (buf,sizeof (buf),"0123456789abcde" ),15 ); +assert_int_equal (buf[9 ],'\0' ); + +memset (buf,'b' ,sizeof (buf)); +assert_int_equal (snprintf (buf,sizeof (buf),"- %d - %d -" ,77 ,88 ),11 ); +assert_int_equal (buf[9 ],'\0' ); + +memset (buf,'c' ,sizeof (buf)); +assert_int_equal (snprintf (buf,sizeof (buf),"- %8.2f" ,77.8899 ),10 ); +assert_int_equal (buf[9 ],'\0' ); +} +int main (void ) {
@@ -387,6 +411,7 @@cmocka_unit_test (test_buffer_free_gc_two),cmocka_unit_test (test_buffer_gc_realloc),cmocka_unit_test (test_character_class), + cmocka_unit_test(test_snprintf) };return cmocka_run_group_tests_name ("buffer" , tests,NULL ,NULL );
tests/unit_tests/openvpn/test_cryptoapi.c +5 -5
@@ -271,7 +271,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); ctx =find_certificate_in_store (select_string, user_store);if (ctx) {
@@ -304,7 +304,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); +snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the common name. But the returned cert may not exactly match
@@ -337,7 +337,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); +snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the issuer. But the returned cert may not exactly match
@@ -411,7 +411,7 @@ {continue ; } -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (Load_CryptoAPI_certificate (select_string, &x509, &privkey) !=1 ) {fail_msg ("Load_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
@@ -446,7 +446,7 @@SSL_CTX *ssl_ctx =SSL_CTX_new_ex (tls_libctx,NULL ,SSLv23_client_method ());assert_non_null (ssl_ctx); -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (!SSL_CTX_use_CryptoAPI_certificate (ssl_ctx, select_string)) {fail_msg ("SSL_CTX_use_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
tests/unit_tests/openvpn/test_pkcs11.c +3 -3
@@ -161,7 +161,7 @@ }else if (flags &GET_USER_PASS_PASSWORD_ONLY ) { -openvpn_snprintf (up->password,sizeof (up->password),"%s" ,PIN ); +snprintf (up->password,sizeof (up->password),"%s" ,PIN ); }else {
@@ -204,8 +204,8 @@ {fail_msg ("make tmpfile using template <%s> failed (error = %d)" , softhsm2_conf_path, errno); } -openvpn_snprintf (config,sizeof (config),"directories.tokendir=%s/" , - softhsm2_tokens_path); +snprintf (config,sizeof (config),"directories.tokendir=%s/" , + softhsm2_tokens_path);assert_int_equal (write (fd, config,strlen (config)),strlen (config));close (fd);
Attention is currently required from: flichtenheld.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/547?usp=email )
Change subject: Remove openvpn_snprintf and similar functions
......................................................................
Patch Set 1: Code-Review-1
(1 comment)
Patchset:
PS1:
not -Werror clean yet
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac
Gerrit-Change-Number: 547
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 25 Mar 2024 11:14:07 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, ordex, plaisthos.
Hello flichtenheld, ordex,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
to look at the new patch set (#2).
The following approvals got outdated and were removed:
Code-Review+2 by ordex, Code-Review-1 by plaisthos
The change is no longer submittable: Code-Review and checks~ChecksSubmitRule are unsatisfied now.
Change subject: Remove openvpn_snprintf and similar functions
......................................................................
Remove openvpn_snprintf and similar functions
Old Microsoft versions did strange behaviour but according to the newly added unit test and
https://stackoverflow.com/questions/7706936/is-snprintf-always-null-terminating
this is now standard conforming and we can use the normal snprintf method.
Microsoft own documentation to swprintf also says you nowadays need to define _CRT_NON_CONFORMING_SWPRINTFS to get to non-standard behaviour.
---
M src/openvpn/buffer.c
M src/openvpn/buffer.h
M src/openvpn/crypto.c
M src/openvpn/crypto_mbedtls.c
M src/openvpn/dns.c
M src/openvpn/env_set.c
M src/openvpn/error.c
M src/openvpn/init.c
M src/openvpn/manage.c
M src/openvpn/options.c
M src/openvpn/pkcs11.c
M src/openvpn/platform.c
M src/openvpn/plugin.c
M src/openvpn/pool.c
M src/openvpn/proxy.c
M src/openvpn/ps.c
M src/openvpn/route.c
M src/openvpn/run_command.h
M src/openvpn/socket.c
M src/openvpn/socks.c
M src/openvpn/ssl_mbedtls.c
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_openssl.c
M src/openvpn/ssl_verify.c
M src/openvpn/ssl_verify_mbedtls.c
M src/openvpn/ssl_verify_openssl.c
M src/openvpn/tls_crypt.c
M src/openvpn/tun.c
M src/openvpn/win32.c
M src/openvpn/win32.h
M src/openvpn/xkey_helper.c
M src/openvpnserv/common.c
M src/openvpnserv/interactive.c
M src/openvpnserv/service.h
M src/openvpnserv/validate.c
M tests/unit_tests/openvpn/test_buffer.c
M tests/unit_tests/openvpn/test_cryptoapi.c
M tests/unit_tests/openvpn/test_pkcs11.c
38 files changed, 288 insertions(+), 333 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/47/547/2
src/openvpn/buffer.c +0 -26
@@ -279,32 +279,6 @@return ret; } - -/* -* This is necessary due to certain buggy implementations of snprintf, -* that don't guarantee null termination for size > 0. -* -* Return false on overflow. -* -* This functionality is duplicated in src/openvpnserv/common.c -* Any modifications here should be done to the other place as well. -*/ - -bool -openvpn_snprintf (char *str,size_t size,const char *format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vsnprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =0 ; - } -return (len >=0 && len < size); -} -/* * write a string to the end of a buffer that was * truncated by buf_printf
src/openvpn/buffer.h +0 -13
@@ -448,19 +448,6 @@*/ bool buf_puts (struct buffer *buf,const char *str); -/* -* Like snprintf but guarantees null termination for size > 0 -*/ -bool openvpn_snprintf(char *str, size_t size, const char *format, ...) -#ifdef __GNUC__ -#if __USE_MINGW_ANSI_STDIO -__attribute__ ((format(gnu_printf, 3, 4))) -#else -__attribute__ ((format(__printf__, 3, 4))) -#endif -#endif -; -/* * remove/add trailing characters
src/openvpn/crypto.c +2 -2
@@ -874,11 +874,11 @@key_direction_state_init (&kds, key_direction); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name);init_key_ctx (&ctx->encrypt, &key2->keys[kds.out_key], kt,OPENVPN_OP_ENCRYPT , log_prefix); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name);init_key_ctx (&ctx->decrypt, &key2->keys[kds.in_key], kt,OPENVPN_OP_DECRYPT , log_prefix);
src/openvpn/crypto_mbedtls.c +5 -5
@@ -128,7 +128,7 @@ {char prefix[256 ]; -if (!openvpn_snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) +if (!snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) {return mbed_log_err (flags, errval, func); }
@@ -239,11 +239,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) {return false; }
@@ -278,11 +278,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----" , name)) {return false; }
src/openvpn/dns.c +2 -2
@@ -349,11 +349,11 @@if (j <0 ) { - name_ok =openvpn_snprintf (name,sizeof (name), format, i); + name_ok =snprintf (name,sizeof (name), format, i); }else { - name_ok =openvpn_snprintf (name,sizeof (name), format, i, j); + name_ok =snprintf (name,sizeof (name), format, i, j); }if (!name_ok)
src/openvpn/env_set.c +4 -4
@@ -259,7 +259,7 @@ setenv_counter(struct env_set *es, const char *name, counter_type value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf), counter_format, value); +snprintf (buf,sizeof (buf), counter_format, value);setenv_str (es, name, buf); }
@@ -267,7 +267,7 @@ setenv_int(struct env_set *es, const char *name, int value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%d" , value); +snprintf (buf,sizeof (buf),"%d" , value);setenv_str (es, name, buf); }
@@ -275,7 +275,7 @@ setenv_long_long(struct env_set *es, const char *name, long long value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value); +snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value);setenv_str (es, name, buf); }
@@ -310,7 +310,7 @@strcpy (tmpname, name);while (NULL !=env_set_get (es, tmpname) && counter <1000 ) { -ASSERT (openvpn_snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); +ASSERT (snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); counter++; }if (counter <1000 )
src/openvpn/error.c +7 -7
@@ -274,14 +274,14 @@if ((flags &M_ERRNO ) && e) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , - m1,openvpn_strerror (e, crt_error, &gc), e); +snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , + m1,openvpn_strerror (e, crt_error, &gc), e);SWAP ; }if (flags &M_OPTERR ) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1); +snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1);SWAP ; }
@@ -321,10 +321,10 @@const struct virtual_output *vo =msg_get_virtual_output ();if (vo) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , - prefix, - prefix_sep, - m1); +snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , + prefix, + prefix_sep, + m1);virtual_output_print (vo, flags, m2); } }
src/openvpn/init.c +1 -1
@@ -359,7 +359,7 @@char *out =malloc (len);check_malloc_return (out); -openvpn_snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); +snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); *remote = out; }else
src/openvpn/manage.c +4 -4
@@ -515,8 +515,8 @@char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); -openvpn_snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes); +snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); +snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes);msg (M_CLIENT ,">BYTECOUNT:%s,%s" , in, out); }
@@ -528,8 +528,8 @@char in[32 ];char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, *bytes_in_total); -openvpn_snprintf (out,sizeof (out), counter_format, *bytes_out_total); +snprintf (in,sizeof (in), counter_format, *bytes_in_total); +snprintf (out,sizeof (out), counter_format, *bytes_out_total);msg (M_CLIENT ,">BYTECOUNT_CLI:%lu,%s,%s" , mdac->cid, in, out); mdac->bytecount_last_update = now; }
src/openvpn/options.c +4 -4
@@ -1427,7 +1427,7 @@for (int i =1 ; i <= opt_max; ++i) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , i); +snprintf (name,sizeof (name),"foreign_option_%d" , i);const char *env_str =env_set_get (es, name);const char *value =strchr (env_str,'=' ) +1 ;
@@ -1482,7 +1482,7 @@while (o->foreign_option_index < opt_max) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--); +snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--);setenv_del (es, name); } }
@@ -5671,8 +5671,8 @@#ifndef ENABLE_SMALL {char script_name[100 ]; -openvpn_snprintf (script_name,sizeof (script_name), -"--%s script" , type); +snprintf (script_name,sizeof (script_name), +"--%s script" , type);if (check_cmd_access (*script, script_name, (in_chroot ? options->chroot_dir :NULL ))) {
src/openvpn/pkcs11.c +3 -3
@@ -201,7 +201,7 @@CLEAR (token_resp); token_resp.defined = false; token_resp.nocache = true; - openvpn_snprintf( + snprintf( token_resp.username, sizeof(token_resp.username), "Please insert %s token",
@@ -245,7 +245,7 @@ASSERT (token!=NULL ); -openvpn_snprintf (prompt,sizeof (prompt),"%s token" , token->label); +snprintf (prompt,sizeof (prompt),"%s token" , token->label); token_pass.defined = false; token_pass.nocache = true;
@@ -719,7 +719,7 @@ id_resp.defined = false; id_resp.nocache = true; -openvpn_snprintf ( +snprintf ( id_resp.username,sizeof (id_resp.username), "Please specify PKCS#11 id to use"
src/openvpn/platform.c +3 -3
@@ -564,9 +564,9 @@ { ++attempts; -if (!openvpn_snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, - prefix, (unsigned long )get_random (), - (unsigned long )get_random ())) +if (!snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, + prefix, (unsigned long )get_random (), + (unsigned long )get_random ())) {msg (M_WARN ,"ERROR: temporary filename too long" );return NULL ;
src/openvpn/plugin.c +2 -2
@@ -260,7 +260,7 @@ {char full[PATH_MAX ]; -openvpn_snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); +snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); p->handle =dlopen (full,RTLD_NOW ); } else
@@ -409,7 +409,7 @@gc_init (&gc); msg_fmt =gc_malloc (ERR_BUF_SIZE , false, &gc); -openvpn_snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format); +snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format);x_msg_va (msg_flags, msg_fmt, arglist);gc_free (&gc);
src/openvpn/pool.c +1 -1
@@ -766,7 +766,7 @@ifconfig_pool_handle h;in_addr_t local, remote;char buf[256 ]; -openvpn_snprintf (buf,sizeof (buf),"common-name-%d" , i); +snprintf (buf,sizeof (buf),"common-name-%d" , i);#ifdef DUP_CN cn =NULL ;#else
src/openvpn/proxy.c +44 -43
185 lines not on this page · raw message
src/openvpn/ps.c +1 -1
@@ -354,7 +354,7 @@ fnlen =strlen (journal_dir) +strlen (t) +2 ; jfn = (char *)malloc (fnlen);check_malloc_return (jfn); -openvpn_snprintf (jfn, fnlen,"%s/%s" , journal_dir, t); +snprintf (jfn, fnlen,"%s/%s" , journal_dir, t);dmsg (D_PS_PROXY_DEBUG ,"PORT SHARE PROXY: client origin %s -> %s" , jfn, f); fd =platform_open (jfn,O_CREAT |O_TRUNC |O_WRONLY ,S_IRUSR |S_IWUSR |S_IRGRP );if (fd !=-1 )
src/openvpn/route.c +3 -3
@@ -1621,11 +1621,11 @@if (rgi) { -openvpn_snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); +snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); }else { -openvpn_snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); +snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); }bool ret =management_android_control (management,"ROUTE" , out); status = ret ?RTA_SUCCESS :RTA_ERROR ;
@@ -2000,7 +2000,7 @@#elif defined (TARGET_ANDROID )char out[64 ]; -openvpn_snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); +snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); status =management_android_control (management,"ROUTE6" , out);
src/openvpn/run_command.h +2 -2
@@ -66,8 +66,8 @@ {char msg[256 ]; -openvpn_snprintf (msg,sizeof (msg), -"WARNING: Failed running command (%s)" , hook); +snprintf (msg,sizeof (msg), +"WARNING: Failed running command (%s)" , hook);return openvpn_execve_check (a, es, flags |S_SCRIPT , msg); }
src/openvpn/socket.c +6 -6
@@ -2983,11 +2983,11 @@case AF_INET :if (flags &SA_IP_PORT ) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); }inet_ntop (AF_INET , &addr->addr.in4.sin_addr, buf,sizeof (buf));
@@ -2995,7 +2995,7 @@if ((flags &SA_IP_PORT ) && addr->addr.in4.sin_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in4.sin_port)); }break ;
@@ -3006,19 +3006,19 @@struct in_addr ia;memcpy (&ia.s_addr, &addr->addr.in6.sin6_addr.s6_addr[12 ],sizeof (ia.s_addr)); -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix);inet_ntop (AF_INET , &ia, buf,sizeof (buf)); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix);inet_ntop (AF_INET6 , &addr->addr.in6.sin6_addr, buf,sizeof (buf)); }setenv_str (es, name_buf, buf);if ((flags &SA_IP_PORT ) && addr->addr.in6.sin6_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in6.sin6_port)); }break ;
src/openvpn/socks.c +4 -3
@@ -109,9 +109,10 @@ "Authentication not possible."); goto cleanup; } -int sret =openvpn_snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , - (int )strlen (creds.username), creds.username, - (int )strlen (creds.password), creds.password); + +int sret =snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , + (int )strlen (creds.username), creds.username, + (int )strlen (creds.password), creds.password);ASSERT (sret <=sizeof (to_send)); size =send (sd, to_send,strlen (to_send),MSG_NOSIGNAL );
src/openvpn/ssl_mbedtls.c +6 -6
@@ -1531,16 +1531,16 @@char s2[256 ]; s1[0 ] = s2[0 ] =0 ; -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s" , - prefix, -mbedtls_ssl_get_version (ks_ssl->ctx), -mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s" , + prefix, +mbedtls_ssl_get_version (ks_ssl->ctx), +mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); cert =mbedtls_ssl_get_peer_cert (ks_ssl->ctx);if (cert !=NULL ) { -openvpn_snprintf (s2,sizeof (s2),", %u bit key" , - (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); +snprintf (s2,sizeof (s2),", %u bit key" , + (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); }msg (D_HANDSHAKE ,"%s%s" , s1, s2);
src/openvpn/ssl_ncp.c +2 -2
@@ -198,8 +198,8 @@size_t newlen =strlen (o->ncp_ciphers) +1 +strlen (ciphername) +1 ;char *ncp_ciphers =gc_malloc (newlen, false, &o->gc); -ASSERT (openvpn_snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, - ciphername)); +ASSERT (snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, + ciphername)); o->ncp_ciphers = ncp_ciphers; }
src/openvpn/ssl_openssl.c +16 -16
@@ -1774,7 +1774,7 @@if (!biofp) {char fn[256 ]; -openvpn_snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); +snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); biofp =fopen (fn,"w" );ASSERT (biofp); biofp_last_open =time (NULL );
@@ -2116,8 +2116,8 @@#endif /* if OPENSSL_VERSION_NUMBER < 0x30000000L */ } -openvpn_snprintf (buf, buflen,"%d bits %s%s" , -EVP_PKEY_bits (pkey), type, curve); +snprintf (buf, buflen,"%d bits %s%s" , +EVP_PKEY_bits (pkey), type, curve); }/**
@@ -2137,12 +2137,12 @@int signature_nid =X509_get_signature_nid (cert);if (signature_nid !=0 ) { -openvpn_snprintf (sig,sizeof (sig),", signature: %s" , -OBJ_nid2sn (signature_nid)); +snprintf (sig,sizeof (sig),", signature: %s" , +OBJ_nid2sn (signature_nid)); } -openvpn_snprintf (buf, buflen,", peer certificate: %s%s" , - pkeybuf, sig); +snprintf (buf, buflen,", peer certificate: %s%s" , + pkeybuf, sig);EVP_PKEY_free (pkey); }
@@ -2160,8 +2160,8 @@char pkeybuf[128 ] = {0 };print_pkey_details (pkey, pkeybuf,sizeof (pkeybuf)); -openvpn_snprintf (buf, buflen,", peer temporary key: %s" , - pkeybuf); +snprintf (buf, buflen,", peer temporary key: %s" , + pkeybuf);EVP_PKEY_free (pkey); }
@@ -2237,8 +2237,8 @@return ; } -openvpn_snprintf (buf, buflen,", peer signing digest/type: %s %s" , - peer_sig, peer_sig_type); +snprintf (buf, buflen,", peer signing digest/type: %s %s" , + peer_sig, peer_sig_type); }
@@ -2261,11 +2261,11 @@ s1[0 ] = s2[0 ] = s3[0 ] = s4[0 ] =0 ; ciph =SSL_get_current_cipher (ks_ssl->ssl); -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , - prefix, -SSL_get_version (ks_ssl->ssl), -SSL_CIPHER_get_version (ciph), -SSL_CIPHER_get_name (ciph)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , + prefix, +SSL_get_version (ks_ssl->ssl), +SSL_CIPHER_get_version (ciph), +SSL_CIPHER_get_name (ciph));X509 *cert =SSL_get_peer_certificate (ks_ssl->ssl);if (cert)
src/openvpn/ssl_verify.c +11 -11
@@ -421,12 +421,12 @@ }/* export subject name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth);setenv_str (es, envname, subject);#if 0 /* export common name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth);setenv_str (es, envname, common_name);#endif
@@ -435,24 +435,24 @@struct buffer sha1 =x509_get_sha1_fingerprint (peer_cert, &gc);struct buffer sha256 =x509_get_sha256_fingerprint (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha1),BLEN (&sha1),0 ,1 ,":" , &gc)); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , - cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , + cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha256),BLEN (&sha256),0 ,1 ,":" , &gc)); }/* export serial number as environmental variable */ serial =backend_x509_get_serial (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth);setenv_str (es, envname, serial);/* export serial number in hex as environmental variable */ serial =backend_x509_get_serial_hex (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth);setenv_str (es, envname, serial);gc_free (&gc);
@@ -569,7 +569,7 @@ goto cleanup; } -if (!openvpn_snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) +if (!snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) {msg (D_HANDSHAKE ,"VERIFY CRL: filename overflow" ); goto cleanup;
@@ -938,9 +938,9 @@if (!check_auth_pending_method (multi->peer_info, pending_method)) {char buf[128 ]; -openvpn_snprintf (buf,sizeof (buf), -"Authentication failed, required pending auth " -"method '%s' not supported" , pending_method); +snprintf (buf,sizeof (buf), +"Authentication failed, required pending auth " +"method '%s' not supported" , pending_method);auth_set_client_reason (multi, buf);msg (M_INFO ,"Client does not supported auth pending method " "'%s'" , pending_method);
src/openvpn/ssl_verify_mbedtls.c +7 -7
@@ -86,8 +86,8 @@char *serial =backend_x509_get_serial (cert, &gc); ret =mbedtls_x509_crt_verify_info (errstr,sizeof (errstr)-1 ,"" , *flags); -if (ret <=0 && !openvpn_snprintf (errstr,sizeof (errstr), -"Could not retrieve error string, flags=%" PRIx32, *flags)) +if (ret <=0 && !snprintf (errstr,sizeof (errstr), +"Could not retrieve error string, flags=%" PRIx32, *flags)) { errstr[0 ] ='\0' ; }
@@ -307,7 +307,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -431,13 +431,13 @@if (0 ==mbedtls_oid_get_attr_short_name (&name->oid, &shortname) ) { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , - cert_depth, shortname); +snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , + cert_depth, shortname); }else { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , - cert_depth); +snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , + cert_depth); }for (i =0 ; i < name->val.len; i++)
src/openvpn/ssl_verify_openssl.c +4 -4
@@ -279,7 +279,7 @@gc_free (&gc);return FAILURE ; } -openvpn_snprintf (common_name, cn_len,"0x%s" , serial); +snprintf (common_name, cn_len,"0x%s" , serial);gc_free (&gc); }else
@@ -454,7 +454,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -597,8 +597,8 @@ name_expand_size =64 +strlen (objbuf); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, - objbuf); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, + objbuf);string_mod (name_expand,CC_PRINT ,CC_CRLF ,'_' );string_mod ((char *)buf,CC_PRINT ,CC_CRLF ,'_' );setenv_str_incr (es, name_expand, (char *)buf);
src/openvpn/tls_crypt.c +2 -2
@@ -574,8 +574,8 @@ }char metadata_type_str[4 ] = {0 };/* Max value: 255 */ -openvpn_snprintf (metadata_type_str,sizeof (metadata_type_str), -"%i" , (uint8_t ) metadata_type); +snprintf (metadata_type_str,sizeof (metadata_type_str), +"%i" , (uint8_t ) metadata_type);struct env_set *es =env_set_create (NULL );setenv_str (es,"script_type" ,"tls-crypt-v2-verify" );setenv_str (es,"metadata_type" , metadata_type_str);
src/openvpn/tun.c +34 -34
164 lines not on this page · raw message
src/openvpn/win32.c +5 -20
@@ -885,8 +885,8 @@char force_path[256 ];char *sysroot =get_win_sys_path (); -if (!openvpn_snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , - sysroot, sysroot, sysroot)) +if (!snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , + sysroot, sysroot, sysroot)) {msg (M_WARN ,"env_block: default path truncated to %s" , force_path); }
@@ -1483,26 +1483,11 @@ }bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vswprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =L'\0' ; - } -return (len >=0 && len < size); -} - -bool get_openvpn_reg_value (const WCHAR *key,WCHAR *value,DWORD size) {WCHAR reg_path[256 ];HKEY hkey; -openvpn_swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME ); +swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME );LONG status =RegOpenKeyExW (HKEY_LOCAL_MACHINE , reg_path,0 ,KEY_READ , &hkey);if (status !=ERROR_SUCCESS )
@@ -1528,7 +1513,7 @@/* if we cannot find installation path from the registry, * use Windows directory as a fallback */ -openvpn_swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); +swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); }if ((install_path[wcslen (install_path) -1 ]) ==L'\\' )
@@ -1553,7 +1538,7 @@if (size ==0 ) {WCHAR val[MAX_PATH ] = {0 }; -openvpn_swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value); +swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value);_wputenv_s (ossl_env[i].name, val); } }
src/openvpn/win32.h +0 -8
@@ -319,14 +319,6 @@int openvpn_execve (const struct argv *a,const struct env_set *es,const unsigned int flags); -/* -* openvpn_swprintf() is currently only used by Windows code paths -* and when enabled for all platforms it will currently break older -* OpenBSD versions lacking vswprintf(3) support in their libc. -*/ -bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -/* Sleep that can be interrupted by signals and exit event */ void win32_sleep (const int n);
src/openvpn/xkey_helper.c +5 -5
@@ -205,7 +205,7 @@ }else { -openvpn_snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); } }else if (!strcmp (alg.keytype,"ED448" ) || !strcmp (alg.keytype,"ED25519" ))
@@ -229,8 +229,8 @@/* For undigested message, add hashalg=digest parameter */ else { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , -"RSA_PKCS1_PADDING" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , +"RSA_PKCS1_PADDING" , alg.mdname); } } else if (!strcmp(alg.padmode, "none") && (flags & MF_EXTERNAL_KEY_NOPADDING)
@@ -240,8 +240,8 @@ }else if (!strcmp (alg.padmode,"pss" ) && (flags &MF_EXTERNAL_KEY_PSSPAD )) { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , -"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , +"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); }else {
src/openvpnserv/common.c +11 -41
102 lines not on this page · raw message
src/openvpnserv/interactive.c +27 -27
159 lines not on this page · raw message
src/openvpnserv/service.h +0 -6
@@ -81,12 +81,6 @@ VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv); -BOOL openvpn_vsntprintf (LPTSTR str,size_t size,LPCTSTR format,va_list arglist); - -BOOL openvpn_sntprintf (LPTSTR str,size_t size,LPCTSTR format, ...); - -BOOL openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -DWORD GetOpenvpnSettings (settings_t *s);BOOL ReportStatusToSCMgr (SERVICE_STATUS_HANDLE service,SERVICE_STATUS *status);
src/openvpnserv/validate.c +1 -1
@@ -68,7 +68,7 @@/* convert fname to full path */ if (PathIsRelativeW (fname) ) { -openvpn_swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); +swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); config_file = tmp; }else
tests/unit_tests/openvpn/test_buffer.c +51 -0
63 lines not on this page · raw message
tests/unit_tests/openvpn/test_cryptoapi.c +5 -5
@@ -271,7 +271,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); ctx =find_certificate_in_store (select_string, user_store);if (ctx) {
@@ -304,7 +304,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); +snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the common name. But the returned cert may not exactly match
@@ -337,7 +337,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); +snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the issuer. But the returned cert may not exactly match
@@ -411,7 +411,7 @@ {continue ; } -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (Load_CryptoAPI_certificate (select_string, &x509, &privkey) !=1 ) {fail_msg ("Load_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
@@ -446,7 +446,7 @@SSL_CTX *ssl_ctx =SSL_CTX_new_ex (tls_libctx,NULL ,SSLv23_client_method ());assert_non_null (ssl_ctx); -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (!SSL_CTX_use_CryptoAPI_certificate (ssl_ctx, select_string)) {fail_msg ("SSL_CTX_use_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
tests/unit_tests/openvpn/test_pkcs11.c +3 -3
@@ -161,7 +161,7 @@ }else if (flags &GET_USER_PASS_PASSWORD_ONLY ) { -openvpn_snprintf (up->password,sizeof (up->password),"%s" ,PIN ); +snprintf (up->password,sizeof (up->password),"%s" ,PIN ); }else {
@@ -204,8 +204,8 @@ {fail_msg ("make tmpfile using template <%s> failed (error = %d)" , softhsm2_conf_path, errno); } -openvpn_snprintf (config,sizeof (config),"directories.tokendir=%s/" , - softhsm2_tokens_path); +snprintf (config,sizeof (config),"directories.tokendir=%s/" , + softhsm2_tokens_path);assert_int_equal (write (fd, config,strlen (config)),strlen (config));close (fd);
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac
Gerrit-Change-Number: 547
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/547?usp=email )
Change subject: Remove openvpn_snprintf and similar functions
......................................................................
Patch Set 2:
(5 comments)
Patchset:
PS2:
some nit picks below..
File src/openvpn/proxy.c:
http://gerrit.openvpn.net/c/openvpn/+/547/comment/d2c89116_22dbc48e :
PS2, Line 962: if (sret >= sizeof(buf))
if this can truly happen, does it mean that the buffer is undersized compared to the size of all variables we are putting together?
Therefore, wouldn't it make more sense to extend the size of the buffer to ensure that no matter what we save in those variables, we will always be able to create the HTTP header?
Or there is a limit with the HTTP header that we have to deal with?
My concern is that we are not preventing people from filling those variables as they please, but we will then fail to put them together for no good reason.
does it make sense?
File src/openvpn/socks.c:
http://gerrit.openvpn.net/c/openvpn/+/547/comment/8bdf0e3c_8356c931 :
PS2, Line 114: (int) strlen(creds.username), creds.username,
normally we don't put a paceb etween the cast and the variable name. This comments applies to all other casts below
http://gerrit.openvpn.net/c/openvpn/+/547/comment/b417986e_a5f333df :
PS2, Line 116: ASSERT(sret <= sizeof(to_send));
why ASSERT here while in other cases we just go to error or cleanup?
File tests/unit_tests/openvpn/test_buffer.c:
http://gerrit.openvpn.net/c/openvpn/+/547/comment/f8c8a505_dbfb9729 :
PS2, Line 369: * for this unit test. We know that are doing this that are truncated
I think there is some typ0 here.
Maybe something like: "We know that results will be truncated and we actually want to test that".
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac
Gerrit-Change-Number: 547
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 27 Mar 2024 10:48:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos.
ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/547?usp=email )
Change subject: Remove openvpn_snprintf and similar functions
......................................................................
Patch Set 2: Code-Review+2
(4 comments)
Patchset:
PS2:
closing some comments as they were commenting code that did not really change with this patch...
The only remaining comment is about a comment in the UT which is a bit cryptic. Maybe that can be adjusted on the fly.
Other than that, the code looks good to me <3
File src/openvpn/proxy.c:
http://gerrit.openvpn.net/c/openvpn/+/547/comment/f78adfbf_ca231ac7 :
PS2, Line 962: if (sret >= sizeof(buf))
Quoted 1 line
if this can truly happen, does it mean that the buffer is undersized compared to the size of all var […]
Done
File src/openvpn/socks.c:
http://gerrit.openvpn.net/c/openvpn/+/547/comment/0f6508ea_b21108c0 :
PS2, Line 114: (int) strlen(creds.username), creds.username,
Quoted 1 line
normally we don't put a paceb etween the cast and the variable name. […]
Done
http://gerrit.openvpn.net/c/openvpn/+/547/comment/b4ed3e45_e9af3876 :
PS2, Line 116: ASSERT(sret <= sizeof(to_send));
Quoted 1 line
why ASSERT here while in other cases we just go to error or cleanup?
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac
Gerrit-Change-Number: 547
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 08 Apr 2024 06:59:00 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment
PATCH v2 1/1 Remove openvpn_snprintf and similar functions
In reply to a message not in the archiveFrom: Arne Schwabe <[email protected]...>
Old Microsoft versions did strange behaviour but according to the newly added unit test and
https://stackoverflow.com/questions/7706936/is-snprintf-always-null-terminating
this is now standard conforming and we can use the normal snprintf method.
Microsoft own documentation to swprintf also says you nowadays need to define _CRT_NON_CONFORMING_SWPRINTFS to get to non-standard behaviour.
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/547
This mail reflects revision 2 of this Change.
Acked-by according to Gerrit (reflected above):
Antonio Quartulli <[email protected]...>
src/openvpn/buffer.c +0 -26
@@ -279,32 +279,6 @@return ret; } - -/* -* This is necessary due to certain buggy implementations of snprintf, -* that don't guarantee null termination for size > 0. -* -* Return false on overflow. -* -* This functionality is duplicated in src/openvpnserv/common.c -* Any modifications here should be done to the other place as well. -*/ - -bool -openvpn_snprintf (char *str,size_t size,const char *format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vsnprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =0 ; - } -return (len >=0 && len < size); -} -/* * write a string to the end of a buffer that was * truncated by buf_printf
src/openvpn/buffer.h +0 -13
@@ -448,19 +448,6 @@*/ bool buf_puts (struct buffer *buf,const char *str); -/* -* Like snprintf but guarantees null termination for size > 0 -*/ -bool openvpn_snprintf(char *str, size_t size, const char *format, ...) -#ifdef __GNUC__ -#if __USE_MINGW_ANSI_STDIO -__attribute__ ((format(gnu_printf, 3, 4))) -#else -__attribute__ ((format(__printf__, 3, 4))) -#endif -#endif -; -/* * remove/add trailing characters
src/openvpn/crypto.c +2 -2
@@ -874,11 +874,11 @@key_direction_state_init (&kds, key_direction); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name);init_key_ctx (&ctx->encrypt, &key2->keys[kds.out_key], kt,OPENVPN_OP_ENCRYPT , log_prefix); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name);init_key_ctx (&ctx->decrypt, &key2->keys[kds.in_key], kt,OPENVPN_OP_DECRYPT , log_prefix);
src/openvpn/crypto_mbedtls.c +5 -5
@@ -128,7 +128,7 @@ {char prefix[256 ]; -if (!openvpn_snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) +if (!snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) {return mbed_log_err (flags, errval, func); }
@@ -239,11 +239,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) {return false; }
@@ -278,11 +278,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----" , name)) {return false; }
src/openvpn/dns.c +2 -2
@@ -349,11 +349,11 @@if (j <0 ) { - name_ok =openvpn_snprintf (name,sizeof (name), format, i); + name_ok =snprintf (name,sizeof (name), format, i); }else { - name_ok =openvpn_snprintf (name,sizeof (name), format, i, j); + name_ok =snprintf (name,sizeof (name), format, i, j); }if (!name_ok)
src/openvpn/env_set.c +4 -4
@@ -259,7 +259,7 @@ setenv_counter(struct env_set *es, const char *name, counter_type value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf), counter_format, value); +snprintf (buf,sizeof (buf), counter_format, value);setenv_str (es, name, buf); }
@@ -267,7 +267,7 @@ setenv_int(struct env_set *es, const char *name, int value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%d" , value); +snprintf (buf,sizeof (buf),"%d" , value);setenv_str (es, name, buf); }
@@ -275,7 +275,7 @@ setenv_long_long(struct env_set *es, const char *name, long long value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value); +snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value);setenv_str (es, name, buf); }
@@ -310,7 +310,7 @@strcpy (tmpname, name);while (NULL !=env_set_get (es, tmpname) && counter <1000 ) { -ASSERT (openvpn_snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); +ASSERT (snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); counter++; }if (counter <1000 )
src/openvpn/error.c +7 -7
@@ -274,14 +274,14 @@if ((flags &M_ERRNO ) && e) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , - m1,openvpn_strerror (e, crt_error, &gc), e); +snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , + m1,openvpn_strerror (e, crt_error, &gc), e);SWAP ; }if (flags &M_OPTERR ) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1); +snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1);SWAP ; }
@@ -321,10 +321,10 @@const struct virtual_output *vo =msg_get_virtual_output ();if (vo) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , - prefix, - prefix_sep, - m1); +snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , + prefix, + prefix_sep, + m1);virtual_output_print (vo, flags, m2); } }
src/openvpn/init.c +1 -1
@@ -359,7 +359,7 @@char *out =malloc (len);check_malloc_return (out); -openvpn_snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); +snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); *remote = out; }else
src/openvpn/manage.c +4 -4
@@ -515,8 +515,8 @@char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); -openvpn_snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes); +snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); +snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes);msg (M_CLIENT ,">BYTECOUNT:%s,%s" , in, out); }
@@ -528,8 +528,8 @@char in[32 ];char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, *bytes_in_total); -openvpn_snprintf (out,sizeof (out), counter_format, *bytes_out_total); +snprintf (in,sizeof (in), counter_format, *bytes_in_total); +snprintf (out,sizeof (out), counter_format, *bytes_out_total);msg (M_CLIENT ,">BYTECOUNT_CLI:%lu,%s,%s" , mdac->cid, in, out); mdac->bytecount_last_update = now; }
src/openvpn/options.c +4 -4
@@ -1427,7 +1427,7 @@for (int i =1 ; i <= opt_max; ++i) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , i); +snprintf (name,sizeof (name),"foreign_option_%d" , i);const char *env_str =env_set_get (es, name);const char *value =strchr (env_str,'=' ) +1 ;
@@ -1482,7 +1482,7 @@while (o->foreign_option_index < opt_max) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--); +snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--);setenv_del (es, name); } }
@@ -5671,8 +5671,8 @@#ifndef ENABLE_SMALL {char script_name[100 ]; -openvpn_snprintf (script_name,sizeof (script_name), -"--%s script" , type); +snprintf (script_name,sizeof (script_name), +"--%s script" , type);if (check_cmd_access (*script, script_name, (in_chroot ? options->chroot_dir :NULL ))) {
src/openvpn/pkcs11.c +3 -3
@@ -201,7 +201,7 @@CLEAR (token_resp); token_resp.defined = false; token_resp.nocache = true; - openvpn_snprintf( + snprintf( token_resp.username, sizeof(token_resp.username), "Please insert %s token",
@@ -245,7 +245,7 @@ASSERT (token!=NULL ); -openvpn_snprintf (prompt,sizeof (prompt),"%s token" , token->label); +snprintf (prompt,sizeof (prompt),"%s token" , token->label); token_pass.defined = false; token_pass.nocache = true;
@@ -719,7 +719,7 @@ id_resp.defined = false; id_resp.nocache = true; -openvpn_snprintf ( +snprintf ( id_resp.username,sizeof (id_resp.username), "Please specify PKCS#11 id to use"
src/openvpn/platform.c +3 -3
@@ -564,9 +564,9 @@ { ++attempts; -if (!openvpn_snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, - prefix, (unsigned long )get_random (), - (unsigned long )get_random ())) +if (!snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, + prefix, (unsigned long )get_random (), + (unsigned long )get_random ())) {msg (M_WARN ,"ERROR: temporary filename too long" );return NULL ;
src/openvpn/plugin.c +2 -2
@@ -260,7 +260,7 @@ {char full[PATH_MAX ]; -openvpn_snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); +snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); p->handle =dlopen (full,RTLD_NOW ); } else
@@ -409,7 +409,7 @@gc_init (&gc); msg_fmt =gc_malloc (ERR_BUF_SIZE , false, &gc); -openvpn_snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format); +snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format);x_msg_va (msg_flags, msg_fmt, arglist);gc_free (&gc);
src/openvpn/pool.c +1 -1
@@ -766,7 +766,7 @@ifconfig_pool_handle h;in_addr_t local, remote;char buf[256 ]; -openvpn_snprintf (buf,sizeof (buf),"common-name-%d" , i); +snprintf (buf,sizeof (buf),"common-name-%d" , i);#ifdef DUP_CN cn =NULL ;#else
src/openvpn/proxy.c +44 -43
185 lines not on this page · raw message
src/openvpn/ps.c +1 -1
@@ -354,7 +354,7 @@ fnlen =strlen (journal_dir) +strlen (t) +2 ; jfn = (char *)malloc (fnlen);check_malloc_return (jfn); -openvpn_snprintf (jfn, fnlen,"%s/%s" , journal_dir, t); +snprintf (jfn, fnlen,"%s/%s" , journal_dir, t);dmsg (D_PS_PROXY_DEBUG ,"PORT SHARE PROXY: client origin %s -> %s" , jfn, f); fd =platform_open (jfn,O_CREAT |O_TRUNC |O_WRONLY ,S_IRUSR |S_IWUSR |S_IRGRP );if (fd !=-1 )
src/openvpn/route.c +3 -3
@@ -1621,11 +1621,11 @@if (rgi) { -openvpn_snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); +snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); }else { -openvpn_snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); +snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); }bool ret =management_android_control (management,"ROUTE" , out); status = ret ?RTA_SUCCESS :RTA_ERROR ;
@@ -2000,7 +2000,7 @@#elif defined (TARGET_ANDROID )char out[64 ]; -openvpn_snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); +snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); status =management_android_control (management,"ROUTE6" , out);
src/openvpn/run_command.h +2 -2
@@ -66,8 +66,8 @@ {char msg[256 ]; -openvpn_snprintf (msg,sizeof (msg), -"WARNING: Failed running command (%s)" , hook); +snprintf (msg,sizeof (msg), +"WARNING: Failed running command (%s)" , hook);return openvpn_execve_check (a, es, flags |S_SCRIPT , msg); }
src/openvpn/socket.c +6 -6
@@ -2983,11 +2983,11 @@case AF_INET :if (flags &SA_IP_PORT ) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); }inet_ntop (AF_INET , &addr->addr.in4.sin_addr, buf,sizeof (buf));
@@ -2995,7 +2995,7 @@if ((flags &SA_IP_PORT ) && addr->addr.in4.sin_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in4.sin_port)); }break ;
@@ -3006,19 +3006,19 @@struct in_addr ia;memcpy (&ia.s_addr, &addr->addr.in6.sin6_addr.s6_addr[12 ],sizeof (ia.s_addr)); -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix);inet_ntop (AF_INET , &ia, buf,sizeof (buf)); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix);inet_ntop (AF_INET6 , &addr->addr.in6.sin6_addr, buf,sizeof (buf)); }setenv_str (es, name_buf, buf);if ((flags &SA_IP_PORT ) && addr->addr.in6.sin6_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in6.sin6_port)); }break ;
src/openvpn/socks.c +4 -3
@@ -109,9 +109,10 @@ "Authentication not possible."); goto cleanup; } -int sret =openvpn_snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , - (int )strlen (creds.username), creds.username, - (int )strlen (creds.password), creds.password); + +int sret =snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , + (int )strlen (creds.username), creds.username, + (int )strlen (creds.password), creds.password);ASSERT (sret <=sizeof (to_send)); size =send (sd, to_send,strlen (to_send),MSG_NOSIGNAL );
src/openvpn/ssl_mbedtls.c +6 -6
@@ -1531,16 +1531,16 @@char s2[256 ]; s1[0 ] = s2[0 ] =0 ; -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s" , - prefix, -mbedtls_ssl_get_version (ks_ssl->ctx), -mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s" , + prefix, +mbedtls_ssl_get_version (ks_ssl->ctx), +mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); cert =mbedtls_ssl_get_peer_cert (ks_ssl->ctx);if (cert !=NULL ) { -openvpn_snprintf (s2,sizeof (s2),", %u bit key" , - (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); +snprintf (s2,sizeof (s2),", %u bit key" , + (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); }msg (D_HANDSHAKE ,"%s%s" , s1, s2);
src/openvpn/ssl_ncp.c +2 -2
@@ -198,8 +198,8 @@size_t newlen =strlen (o->ncp_ciphers) +1 +strlen (ciphername) +1 ;char *ncp_ciphers =gc_malloc (newlen, false, &o->gc); -ASSERT (openvpn_snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, - ciphername)); +ASSERT (snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, + ciphername)); o->ncp_ciphers = ncp_ciphers; }
src/openvpn/ssl_openssl.c +16 -16
@@ -1774,7 +1774,7 @@if (!biofp) {char fn[256 ]; -openvpn_snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); +snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); biofp =fopen (fn,"w" );ASSERT (biofp); biofp_last_open =time (NULL );
@@ -2116,8 +2116,8 @@#endif /* if OPENSSL_VERSION_NUMBER < 0x30000000L */ } -openvpn_snprintf (buf, buflen,"%d bits %s%s" , -EVP_PKEY_bits (pkey), type, curve); +snprintf (buf, buflen,"%d bits %s%s" , +EVP_PKEY_bits (pkey), type, curve); }/**
@@ -2137,12 +2137,12 @@int signature_nid =X509_get_signature_nid (cert);if (signature_nid !=0 ) { -openvpn_snprintf (sig,sizeof (sig),", signature: %s" , -OBJ_nid2sn (signature_nid)); +snprintf (sig,sizeof (sig),", signature: %s" , +OBJ_nid2sn (signature_nid)); } -openvpn_snprintf (buf, buflen,", peer certificate: %s%s" , - pkeybuf, sig); +snprintf (buf, buflen,", peer certificate: %s%s" , + pkeybuf, sig);EVP_PKEY_free (pkey); }
@@ -2160,8 +2160,8 @@char pkeybuf[128 ] = {0 };print_pkey_details (pkey, pkeybuf,sizeof (pkeybuf)); -openvpn_snprintf (buf, buflen,", peer temporary key: %s" , - pkeybuf); +snprintf (buf, buflen,", peer temporary key: %s" , + pkeybuf);EVP_PKEY_free (pkey); }
@@ -2237,8 +2237,8 @@return ; } -openvpn_snprintf (buf, buflen,", peer signing digest/type: %s %s" , - peer_sig, peer_sig_type); +snprintf (buf, buflen,", peer signing digest/type: %s %s" , + peer_sig, peer_sig_type); }
@@ -2261,11 +2261,11 @@ s1[0 ] = s2[0 ] = s3[0 ] = s4[0 ] =0 ; ciph =SSL_get_current_cipher (ks_ssl->ssl); -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , - prefix, -SSL_get_version (ks_ssl->ssl), -SSL_CIPHER_get_version (ciph), -SSL_CIPHER_get_name (ciph)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , + prefix, +SSL_get_version (ks_ssl->ssl), +SSL_CIPHER_get_version (ciph), +SSL_CIPHER_get_name (ciph));X509 *cert =SSL_get_peer_certificate (ks_ssl->ssl);if (cert)
src/openvpn/ssl_verify.c +11 -11
@@ -421,12 +421,12 @@ }/* export subject name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth);setenv_str (es, envname, subject);#if 0 /* export common name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth);setenv_str (es, envname, common_name);#endif
@@ -435,24 +435,24 @@struct buffer sha1 =x509_get_sha1_fingerprint (peer_cert, &gc);struct buffer sha256 =x509_get_sha256_fingerprint (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha1),BLEN (&sha1),0 ,1 ,":" , &gc)); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , - cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , + cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha256),BLEN (&sha256),0 ,1 ,":" , &gc)); }/* export serial number as environmental variable */ serial =backend_x509_get_serial (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth);setenv_str (es, envname, serial);/* export serial number in hex as environmental variable */ serial =backend_x509_get_serial_hex (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth);setenv_str (es, envname, serial);gc_free (&gc);
@@ -569,7 +569,7 @@ goto cleanup; } -if (!openvpn_snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) +if (!snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) {msg (D_HANDSHAKE ,"VERIFY CRL: filename overflow" ); goto cleanup;
@@ -938,9 +938,9 @@if (!check_auth_pending_method (multi->peer_info, pending_method)) {char buf[128 ]; -openvpn_snprintf (buf,sizeof (buf), -"Authentication failed, required pending auth " -"method '%s' not supported" , pending_method); +snprintf (buf,sizeof (buf), +"Authentication failed, required pending auth " +"method '%s' not supported" , pending_method);auth_set_client_reason (multi, buf);msg (M_INFO ,"Client does not supported auth pending method " "'%s'" , pending_method);
src/openvpn/ssl_verify_mbedtls.c +7 -7
@@ -86,8 +86,8 @@char *serial =backend_x509_get_serial (cert, &gc); ret =mbedtls_x509_crt_verify_info (errstr,sizeof (errstr)-1 ,"" , *flags); -if (ret <=0 && !openvpn_snprintf (errstr,sizeof (errstr), -"Could not retrieve error string, flags=%" PRIx32, *flags)) +if (ret <=0 && !snprintf (errstr,sizeof (errstr), +"Could not retrieve error string, flags=%" PRIx32, *flags)) { errstr[0 ] ='\0' ; }
@@ -307,7 +307,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -431,13 +431,13 @@if (0 ==mbedtls_oid_get_attr_short_name (&name->oid, &shortname) ) { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , - cert_depth, shortname); +snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , + cert_depth, shortname); }else { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , - cert_depth); +snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , + cert_depth); }for (i =0 ; i < name->val.len; i++)
src/openvpn/ssl_verify_openssl.c +4 -4
@@ -279,7 +279,7 @@gc_free (&gc);return FAILURE ; } -openvpn_snprintf (common_name, cn_len,"0x%s" , serial); +snprintf (common_name, cn_len,"0x%s" , serial);gc_free (&gc); }else
@@ -454,7 +454,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -597,8 +597,8 @@ name_expand_size =64 +strlen (objbuf); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, - objbuf); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, + objbuf);string_mod (name_expand,CC_PRINT ,CC_CRLF ,'_' );string_mod ((char *)buf,CC_PRINT ,CC_CRLF ,'_' );setenv_str_incr (es, name_expand, (char *)buf);
src/openvpn/tls_crypt.c +2 -2
@@ -574,8 +574,8 @@ }char metadata_type_str[4 ] = {0 };/* Max value: 255 */ -openvpn_snprintf (metadata_type_str,sizeof (metadata_type_str), -"%i" , (uint8_t ) metadata_type); +snprintf (metadata_type_str,sizeof (metadata_type_str), +"%i" , (uint8_t ) metadata_type);struct env_set *es =env_set_create (NULL );setenv_str (es,"script_type" ,"tls-crypt-v2-verify" );setenv_str (es,"metadata_type" , metadata_type_str);
src/openvpn/tun.c +34 -34
164 lines not on this page · raw message
src/openvpn/win32.c +5 -20
@@ -885,8 +885,8 @@char force_path[256 ];char *sysroot =get_win_sys_path (); -if (!openvpn_snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , - sysroot, sysroot, sysroot)) +if (!snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , + sysroot, sysroot, sysroot)) {msg (M_WARN ,"env_block: default path truncated to %s" , force_path); }
@@ -1483,26 +1483,11 @@ }bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vswprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =L'\0' ; - } -return (len >=0 && len < size); -} - -bool get_openvpn_reg_value (const WCHAR *key,WCHAR *value,DWORD size) {WCHAR reg_path[256 ];HKEY hkey; -openvpn_swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME ); +swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME );LONG status =RegOpenKeyExW (HKEY_LOCAL_MACHINE , reg_path,0 ,KEY_READ , &hkey);if (status !=ERROR_SUCCESS )
@@ -1528,7 +1513,7 @@/* if we cannot find installation path from the registry, * use Windows directory as a fallback */ -openvpn_swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); +swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); }if ((install_path[wcslen (install_path) -1 ]) ==L'\\' )
@@ -1553,7 +1538,7 @@if (size ==0 ) {WCHAR val[MAX_PATH ] = {0 }; -openvpn_swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value); +swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value);_wputenv_s (ossl_env[i].name, val); } }
src/openvpn/win32.h +0 -8
@@ -319,14 +319,6 @@int openvpn_execve (const struct argv *a,const struct env_set *es,const unsigned int flags); -/* -* openvpn_swprintf() is currently only used by Windows code paths -* and when enabled for all platforms it will currently break older -* OpenBSD versions lacking vswprintf(3) support in their libc. -*/ -bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -/* Sleep that can be interrupted by signals and exit event */ void win32_sleep (const int n);
src/openvpn/xkey_helper.c +5 -5
@@ -205,7 +205,7 @@ }else { -openvpn_snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); } }else if (!strcmp (alg.keytype,"ED448" ) || !strcmp (alg.keytype,"ED25519" ))
@@ -229,8 +229,8 @@/* For undigested message, add hashalg=digest parameter */ else { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , -"RSA_PKCS1_PADDING" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , +"RSA_PKCS1_PADDING" , alg.mdname); } } else if (!strcmp(alg.padmode, "none") && (flags & MF_EXTERNAL_KEY_NOPADDING)
@@ -240,8 +240,8 @@ }else if (!strcmp (alg.padmode,"pss" ) && (flags &MF_EXTERNAL_KEY_PSSPAD )) { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , -"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , +"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); }else {
src/openvpnserv/common.c +11 -41
102 lines not on this page · raw message
src/openvpnserv/interactive.c +27 -27
159 lines not on this page · raw message
src/openvpnserv/service.h +0 -6
@@ -81,12 +81,6 @@ VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv); -BOOL openvpn_vsntprintf (LPTSTR str,size_t size,LPCTSTR format,va_list arglist); - -BOOL openvpn_sntprintf (LPTSTR str,size_t size,LPCTSTR format, ...); - -BOOL openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -DWORD GetOpenvpnSettings (settings_t *s);BOOL ReportStatusToSCMgr (SERVICE_STATUS_HANDLE service,SERVICE_STATUS *status);
src/openvpnserv/validate.c +1 -1
@@ -68,7 +68,7 @@/* convert fname to full path */ if (PathIsRelativeW (fname) ) { -openvpn_swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); +swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); config_file = tmp; }else
tests/unit_tests/openvpn/test_buffer.c +51 -0
63 lines not on this page · raw message
tests/unit_tests/openvpn/test_cryptoapi.c +5 -5
@@ -271,7 +271,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); ctx =find_certificate_in_store (select_string, user_store);if (ctx) {
@@ -304,7 +304,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); +snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the common name. But the returned cert may not exactly match
@@ -337,7 +337,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); +snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the issuer. But the returned cert may not exactly match
@@ -411,7 +411,7 @@ {continue ; } -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (Load_CryptoAPI_certificate (select_string, &x509, &privkey) !=1 ) {fail_msg ("Load_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
@@ -446,7 +446,7 @@SSL_CTX *ssl_ctx =SSL_CTX_new_ex (tls_libctx,NULL ,SSLv23_client_method ());assert_non_null (ssl_ctx); -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (!SSL_CTX_use_CryptoAPI_certificate (ssl_ctx, select_string)) {fail_msg ("SSL_CTX_use_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
tests/unit_tests/openvpn/test_pkcs11.c +3 -3
@@ -161,7 +161,7 @@ }else if (flags &GET_USER_PASS_PASSWORD_ONLY ) { -openvpn_snprintf (up->password,sizeof (up->password),"%s" ,PIN ); +snprintf (up->password,sizeof (up->password),"%s" ,PIN ); }else {
@@ -204,8 +204,8 @@ {fail_msg ("make tmpfile using template <%s> failed (error = %d)" , softhsm2_conf_path, errno); } -openvpn_snprintf (config,sizeof (config),"directories.tokendir=%s/" , - softhsm2_tokens_path); +snprintf (config,sizeof (config),"directories.tokendir=%s/" , + softhsm2_tokens_path);assert_int_equal (write (fd, config,strlen (config)),strlen (config));close (fd);
Attention is currently required from: flichtenheld, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/547?usp=email )
Change subject: Remove openvpn_snprintf and similar functions
......................................................................
Patch Set 2: Code-Review-1
(3 comments)
Patchset:
PS2:
Unfortunately, this fails -Werror msbuild builds now, see comment in interactive.c
File src/openvpn/proxy.c:
http://gerrit.openvpn.net/c/openvpn/+/547/comment/b37effa6_d450b13a :
PS2, Line 962: if (sret >= sizeof(buf))
Quoted 1 line
if this can truly happen, does it mean that the buffer is undersized compared to the size of all var […]
this code is not part of the actual patchset, but a gerrit artefact due to rebasing. *This* patchset only replaces openvpn_snprintf() with snprintf().
File src/openvpnserv/interactive.c:
http://gerrit.openvpn.net/c/openvpn/+/547/comment/918c9772_0150ba41 :
PS2, Line 2007: sud.options, svc_pipe);
This makes GHA msbuild build fails now, with
``` D:\a\openvpn\openvpn\src\openvpnserv\interactive.c(2006,37): warning C4477: 'swprintf' : format string '%llu' requires an argument of type 'unsigned __int64', but variadic argument 2 has type 'HANDLE' [D:\a\openvpn\openvpn\out\build\win-amd64-release\src\openvpnserv\openvpnserv.vcxproj] ```
so it seems the cast to something-int (DWORD?) is needed.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac
Gerrit-Change-Number: 547
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 08 Apr 2024 08:22:27 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld, ordex, plaisthos.
Hello cron2, flichtenheld, ordex,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
to look at the new patch set (#3).
The following approvals got outdated and were removed:
Code-Review+2 by ordex, Code-Review-1 by cron2
The change is no longer submittable: Code-Review and checks~ChecksSubmitRule are unsatisfied now.
Change subject: Remove openvpn_snprintf and similar functions
......................................................................
Remove openvpn_snprintf and similar functions
Old Microsoft versions did strange behaviour but according to the newly added unit test and
https://stackoverflow.com/questions/7706936/is-snprintf-always-null-terminating
this is now standard conforming and we can use the normal snprintf method.
Microsoft own documentation to swprintf also says you nowadays need to define _CRT_NON_CONFORMING_SWPRINTFS to get to non-standard behaviour.
---
M src/openvpn/buffer.c
M src/openvpn/buffer.h
M src/openvpn/crypto.c
M src/openvpn/crypto_mbedtls.c
M src/openvpn/dns.c
M src/openvpn/env_set.c
M src/openvpn/error.c
M src/openvpn/init.c
M src/openvpn/manage.c
M src/openvpn/options.c
M src/openvpn/pkcs11.c
M src/openvpn/platform.c
M src/openvpn/plugin.c
M src/openvpn/pool.c
M src/openvpn/proxy.c
M src/openvpn/ps.c
M src/openvpn/route.c
M src/openvpn/run_command.h
M src/openvpn/socket.c
M src/openvpn/socks.c
M src/openvpn/ssl_mbedtls.c
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_openssl.c
M src/openvpn/ssl_verify.c
M src/openvpn/ssl_verify_mbedtls.c
M src/openvpn/ssl_verify_openssl.c
M src/openvpn/tls_crypt.c
M src/openvpn/tun.c
M src/openvpn/win32.c
M src/openvpn/win32.h
M src/openvpn/xkey_helper.c
M src/openvpnserv/common.c
M src/openvpnserv/interactive.c
M src/openvpnserv/service.h
M src/openvpnserv/validate.c
M tests/unit_tests/openvpn/test_buffer.c
M tests/unit_tests/openvpn/test_cryptoapi.c
M tests/unit_tests/openvpn/test_pkcs11.c
38 files changed, 291 insertions(+), 333 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/47/547/3
src/openvpn/buffer.c +0 -26
@@ -279,32 +279,6 @@return ret; } - -/* -* This is necessary due to certain buggy implementations of snprintf, -* that don't guarantee null termination for size > 0. -* -* Return false on overflow. -* -* This functionality is duplicated in src/openvpnserv/common.c -* Any modifications here should be done to the other place as well. -*/ - -bool -openvpn_snprintf (char *str,size_t size,const char *format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vsnprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =0 ; - } -return (len >=0 && len < size); -} -/* * write a string to the end of a buffer that was * truncated by buf_printf
src/openvpn/buffer.h +0 -13
@@ -448,19 +448,6 @@*/ bool buf_puts (struct buffer *buf,const char *str); -/* -* Like snprintf but guarantees null termination for size > 0 -*/ -bool openvpn_snprintf(char *str, size_t size, const char *format, ...) -#ifdef __GNUC__ -#if __USE_MINGW_ANSI_STDIO -__attribute__ ((format(gnu_printf, 3, 4))) -#else -__attribute__ ((format(__printf__, 3, 4))) -#endif -#endif -; -/* * remove/add trailing characters
src/openvpn/crypto.c +2 -2
@@ -874,11 +874,11 @@key_direction_state_init (&kds, key_direction); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name);init_key_ctx (&ctx->encrypt, &key2->keys[kds.out_key], kt,OPENVPN_OP_ENCRYPT , log_prefix); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name);init_key_ctx (&ctx->decrypt, &key2->keys[kds.in_key], kt,OPENVPN_OP_DECRYPT , log_prefix);
src/openvpn/crypto_mbedtls.c +5 -5
@@ -128,7 +128,7 @@ {char prefix[256 ]; -if (!openvpn_snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) +if (!snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) {return mbed_log_err (flags, errval, func); }
@@ -239,11 +239,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) {return false; }
@@ -278,11 +278,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----" , name)) {return false; }
src/openvpn/dns.c +2 -2
@@ -349,11 +349,11 @@if (j <0 ) { - name_ok =openvpn_snprintf (name,sizeof (name), format, i); + name_ok =snprintf (name,sizeof (name), format, i); }else { - name_ok =openvpn_snprintf (name,sizeof (name), format, i, j); + name_ok =snprintf (name,sizeof (name), format, i, j); }if (!name_ok)
src/openvpn/env_set.c +4 -4
@@ -259,7 +259,7 @@ setenv_counter(struct env_set *es, const char *name, counter_type value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf), counter_format, value); +snprintf (buf,sizeof (buf), counter_format, value);setenv_str (es, name, buf); }
@@ -267,7 +267,7 @@ setenv_int(struct env_set *es, const char *name, int value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%d" , value); +snprintf (buf,sizeof (buf),"%d" , value);setenv_str (es, name, buf); }
@@ -275,7 +275,7 @@ setenv_long_long(struct env_set *es, const char *name, long long value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value); +snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value);setenv_str (es, name, buf); }
@@ -310,7 +310,7 @@strcpy (tmpname, name);while (NULL !=env_set_get (es, tmpname) && counter <1000 ) { -ASSERT (openvpn_snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); +ASSERT (snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); counter++; }if (counter <1000 )
src/openvpn/error.c +7 -7
@@ -274,14 +274,14 @@if ((flags &M_ERRNO ) && e) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , - m1,openvpn_strerror (e, crt_error, &gc), e); +snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , + m1,openvpn_strerror (e, crt_error, &gc), e);SWAP ; }if (flags &M_OPTERR ) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1); +snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1);SWAP ; }
@@ -321,10 +321,10 @@const struct virtual_output *vo =msg_get_virtual_output ();if (vo) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , - prefix, - prefix_sep, - m1); +snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , + prefix, + prefix_sep, + m1);virtual_output_print (vo, flags, m2); } }
src/openvpn/init.c +1 -1
@@ -359,7 +359,7 @@char *out =malloc (len);check_malloc_return (out); -openvpn_snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); +snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); *remote = out; }else
src/openvpn/manage.c +4 -4
@@ -515,8 +515,8 @@char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); -openvpn_snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes); +snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); +snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes);msg (M_CLIENT ,">BYTECOUNT:%s,%s" , in, out); }
@@ -528,8 +528,8 @@char in[32 ];char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, *bytes_in_total); -openvpn_snprintf (out,sizeof (out), counter_format, *bytes_out_total); +snprintf (in,sizeof (in), counter_format, *bytes_in_total); +snprintf (out,sizeof (out), counter_format, *bytes_out_total);msg (M_CLIENT ,">BYTECOUNT_CLI:%lu,%s,%s" , mdac->cid, in, out); mdac->bytecount_last_update = now; }
src/openvpn/options.c +4 -4
@@ -1427,7 +1427,7 @@for (int i =1 ; i <= opt_max; ++i) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , i); +snprintf (name,sizeof (name),"foreign_option_%d" , i);const char *env_str =env_set_get (es, name);const char *value =strchr (env_str,'=' ) +1 ;
@@ -1482,7 +1482,7 @@while (o->foreign_option_index < opt_max) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--); +snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--);setenv_del (es, name); } }
@@ -5674,8 +5674,8 @@#ifndef ENABLE_SMALL {char script_name[100 ]; -openvpn_snprintf (script_name,sizeof (script_name), -"--%s script" , type); +snprintf (script_name,sizeof (script_name), +"--%s script" , type);if (check_cmd_access (*script, script_name, (in_chroot ? options->chroot_dir :NULL ))) {
src/openvpn/pkcs11.c +3 -3
@@ -201,7 +201,7 @@CLEAR (token_resp); token_resp.defined = false; token_resp.nocache = true; - openvpn_snprintf( + snprintf( token_resp.username, sizeof(token_resp.username), "Please insert %s token",
@@ -245,7 +245,7 @@ASSERT (token!=NULL ); -openvpn_snprintf (prompt,sizeof (prompt),"%s token" , token->label); +snprintf (prompt,sizeof (prompt),"%s token" , token->label); token_pass.defined = false; token_pass.nocache = true;
@@ -719,7 +719,7 @@ id_resp.defined = false; id_resp.nocache = true; -openvpn_snprintf ( +snprintf ( id_resp.username,sizeof (id_resp.username), "Please specify PKCS#11 id to use"
src/openvpn/platform.c +3 -3
@@ -564,9 +564,9 @@ { ++attempts; -if (!openvpn_snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, - prefix, (unsigned long )get_random (), - (unsigned long )get_random ())) +if (!snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, + prefix, (unsigned long )get_random (), + (unsigned long )get_random ())) {msg (M_WARN ,"ERROR: temporary filename too long" );return NULL ;
src/openvpn/plugin.c +2 -2
@@ -260,7 +260,7 @@ {char full[PATH_MAX ]; -openvpn_snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); +snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); p->handle =dlopen (full,RTLD_NOW ); } else
@@ -409,7 +409,7 @@gc_init (&gc); msg_fmt =gc_malloc (ERR_BUF_SIZE , false, &gc); -openvpn_snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format); +snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format);x_msg_va (msg_flags, msg_fmt, arglist);gc_free (&gc);
src/openvpn/pool.c +1 -1
@@ -766,7 +766,7 @@ifconfig_pool_handle h;in_addr_t local, remote;char buf[256 ]; -openvpn_snprintf (buf,sizeof (buf),"common-name-%d" , i); +snprintf (buf,sizeof (buf),"common-name-%d" , i);#ifdef DUP_CN cn =NULL ;#else
src/openvpn/proxy.c +44 -43
185 lines not on this page · raw message
src/openvpn/ps.c +1 -1
@@ -354,7 +354,7 @@ fnlen =strlen (journal_dir) +strlen (t) +2 ; jfn = (char *)malloc (fnlen);check_malloc_return (jfn); -openvpn_snprintf (jfn, fnlen,"%s/%s" , journal_dir, t); +snprintf (jfn, fnlen,"%s/%s" , journal_dir, t);dmsg (D_PS_PROXY_DEBUG ,"PORT SHARE PROXY: client origin %s -> %s" , jfn, f); fd =platform_open (jfn,O_CREAT |O_TRUNC |O_WRONLY ,S_IRUSR |S_IWUSR |S_IRGRP );if (fd !=-1 )
src/openvpn/route.c +3 -3
@@ -1621,11 +1621,11 @@if (rgi) { -openvpn_snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); +snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); }else { -openvpn_snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); +snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); }bool ret =management_android_control (management,"ROUTE" , out); status = ret ?RTA_SUCCESS :RTA_ERROR ;
@@ -2000,7 +2000,7 @@#elif defined (TARGET_ANDROID )char out[64 ]; -openvpn_snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); +snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); status =management_android_control (management,"ROUTE6" , out);
src/openvpn/run_command.h +2 -2
@@ -66,8 +66,8 @@ {char msg[256 ]; -openvpn_snprintf (msg,sizeof (msg), -"WARNING: Failed running command (%s)" , hook); +snprintf (msg,sizeof (msg), +"WARNING: Failed running command (%s)" , hook);return openvpn_execve_check (a, es, flags |S_SCRIPT , msg); }
src/openvpn/socket.c +6 -6
@@ -2983,11 +2983,11 @@case AF_INET :if (flags &SA_IP_PORT ) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); }inet_ntop (AF_INET , &addr->addr.in4.sin_addr, buf,sizeof (buf));
@@ -2995,7 +2995,7 @@if ((flags &SA_IP_PORT ) && addr->addr.in4.sin_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in4.sin_port)); }break ;
@@ -3006,19 +3006,19 @@struct in_addr ia;memcpy (&ia.s_addr, &addr->addr.in6.sin6_addr.s6_addr[12 ],sizeof (ia.s_addr)); -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix);inet_ntop (AF_INET , &ia, buf,sizeof (buf)); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix);inet_ntop (AF_INET6 , &addr->addr.in6.sin6_addr, buf,sizeof (buf)); }setenv_str (es, name_buf, buf);if ((flags &SA_IP_PORT ) && addr->addr.in6.sin6_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in6.sin6_port)); }break ;
src/openvpn/socks.c +4 -3
@@ -109,9 +109,10 @@ "Authentication not possible."); goto cleanup; } -int sret =openvpn_snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , - (int )strlen (creds.username), creds.username, - (int )strlen (creds.password), creds.password); + +int sret =snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , + (int )strlen (creds.username), creds.username, + (int )strlen (creds.password), creds.password);ASSERT (sret <=sizeof (to_send)); size =send (sd, to_send,strlen (to_send),MSG_NOSIGNAL );
src/openvpn/ssl_mbedtls.c +6 -6
@@ -1531,16 +1531,16 @@char s2[256 ]; s1[0 ] = s2[0 ] =0 ; -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s" , - prefix, -mbedtls_ssl_get_version (ks_ssl->ctx), -mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s" , + prefix, +mbedtls_ssl_get_version (ks_ssl->ctx), +mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); cert =mbedtls_ssl_get_peer_cert (ks_ssl->ctx);if (cert !=NULL ) { -openvpn_snprintf (s2,sizeof (s2),", %u bit key" , - (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); +snprintf (s2,sizeof (s2),", %u bit key" , + (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); }msg (D_HANDSHAKE ,"%s%s" , s1, s2);
src/openvpn/ssl_ncp.c +2 -2
@@ -198,8 +198,8 @@size_t newlen =strlen (o->ncp_ciphers) +1 +strlen (ciphername) +1 ;char *ncp_ciphers =gc_malloc (newlen, false, &o->gc); -ASSERT (openvpn_snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, - ciphername)); +ASSERT (snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, + ciphername)); o->ncp_ciphers = ncp_ciphers; }
src/openvpn/ssl_openssl.c +16 -16
@@ -1774,7 +1774,7 @@if (!biofp) {char fn[256 ]; -openvpn_snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); +snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); biofp =fopen (fn,"w" );ASSERT (biofp); biofp_last_open =time (NULL );
@@ -2116,8 +2116,8 @@#endif /* if OPENSSL_VERSION_NUMBER < 0x30000000L */ } -openvpn_snprintf (buf, buflen,"%d bits %s%s" , -EVP_PKEY_bits (pkey), type, curve); +snprintf (buf, buflen,"%d bits %s%s" , +EVP_PKEY_bits (pkey), type, curve); }/**
@@ -2137,12 +2137,12 @@int signature_nid =X509_get_signature_nid (cert);if (signature_nid !=0 ) { -openvpn_snprintf (sig,sizeof (sig),", signature: %s" , -OBJ_nid2sn (signature_nid)); +snprintf (sig,sizeof (sig),", signature: %s" , +OBJ_nid2sn (signature_nid)); } -openvpn_snprintf (buf, buflen,", peer certificate: %s%s" , - pkeybuf, sig); +snprintf (buf, buflen,", peer certificate: %s%s" , + pkeybuf, sig);EVP_PKEY_free (pkey); }
@@ -2160,8 +2160,8 @@char pkeybuf[128 ] = {0 };print_pkey_details (pkey, pkeybuf,sizeof (pkeybuf)); -openvpn_snprintf (buf, buflen,", peer temporary key: %s" , - pkeybuf); +snprintf (buf, buflen,", peer temporary key: %s" , + pkeybuf);EVP_PKEY_free (pkey); }
@@ -2238,8 +2238,8 @@return ; } -openvpn_snprintf (buf, buflen,", peer signing digest/type: %s %s" , - peer_sig, peer_sig_type); +snprintf (buf, buflen,", peer signing digest/type: %s %s" , + peer_sig, peer_sig_type); }
@@ -2262,11 +2262,11 @@ s1[0 ] = s2[0 ] = s3[0 ] = s4[0 ] =0 ; ciph =SSL_get_current_cipher (ks_ssl->ssl); -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , - prefix, -SSL_get_version (ks_ssl->ssl), -SSL_CIPHER_get_version (ciph), -SSL_CIPHER_get_name (ciph)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , + prefix, +SSL_get_version (ks_ssl->ssl), +SSL_CIPHER_get_version (ciph), +SSL_CIPHER_get_name (ciph));X509 *cert =SSL_get_peer_certificate (ks_ssl->ssl);if (cert)
src/openvpn/ssl_verify.c +11 -11
@@ -421,12 +421,12 @@ }/* export subject name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth);setenv_str (es, envname, subject);#if 0 /* export common name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth);setenv_str (es, envname, common_name);#endif
@@ -435,24 +435,24 @@struct buffer sha1 =x509_get_sha1_fingerprint (peer_cert, &gc);struct buffer sha256 =x509_get_sha256_fingerprint (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha1),BLEN (&sha1),0 ,1 ,":" , &gc)); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , - cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , + cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha256),BLEN (&sha256),0 ,1 ,":" , &gc)); }/* export serial number as environmental variable */ serial =backend_x509_get_serial (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth);setenv_str (es, envname, serial);/* export serial number in hex as environmental variable */ serial =backend_x509_get_serial_hex (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth);setenv_str (es, envname, serial);gc_free (&gc);
@@ -569,7 +569,7 @@ goto cleanup; } -if (!openvpn_snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) +if (!snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) {msg (D_HANDSHAKE ,"VERIFY CRL: filename overflow" ); goto cleanup;
@@ -938,9 +938,9 @@if (!check_auth_pending_method (multi->peer_info, pending_method)) {char buf[128 ]; -openvpn_snprintf (buf,sizeof (buf), -"Authentication failed, required pending auth " -"method '%s' not supported" , pending_method); +snprintf (buf,sizeof (buf), +"Authentication failed, required pending auth " +"method '%s' not supported" , pending_method);auth_set_client_reason (multi, buf);msg (M_INFO ,"Client does not supported auth pending method " "'%s'" , pending_method);
src/openvpn/ssl_verify_mbedtls.c +7 -7
@@ -86,8 +86,8 @@char *serial =backend_x509_get_serial (cert, &gc); ret =mbedtls_x509_crt_verify_info (errstr,sizeof (errstr)-1 ,"" , *flags); -if (ret <=0 && !openvpn_snprintf (errstr,sizeof (errstr), -"Could not retrieve error string, flags=%" PRIx32, *flags)) +if (ret <=0 && !snprintf (errstr,sizeof (errstr), +"Could not retrieve error string, flags=%" PRIx32, *flags)) { errstr[0 ] ='\0' ; }
@@ -307,7 +307,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -431,13 +431,13 @@if (0 ==mbedtls_oid_get_attr_short_name (&name->oid, &shortname) ) { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , - cert_depth, shortname); +snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , + cert_depth, shortname); }else { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , - cert_depth); +snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , + cert_depth); }for (i =0 ; i < name->val.len; i++)
src/openvpn/ssl_verify_openssl.c +4 -4
@@ -279,7 +279,7 @@gc_free (&gc);return FAILURE ; } -openvpn_snprintf (common_name, cn_len,"0x%s" , serial); +snprintf (common_name, cn_len,"0x%s" , serial);gc_free (&gc); }else
@@ -454,7 +454,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -597,8 +597,8 @@ name_expand_size =64 +strlen (objbuf); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, - objbuf); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, + objbuf);string_mod (name_expand,CC_PRINT ,CC_CRLF ,'_' );string_mod ((char *)buf,CC_PRINT ,CC_CRLF ,'_' );setenv_str_incr (es, name_expand, (char *)buf);
src/openvpn/tls_crypt.c +2 -2
@@ -574,8 +574,8 @@ }char metadata_type_str[4 ] = {0 };/* Max value: 255 */ -openvpn_snprintf (metadata_type_str,sizeof (metadata_type_str), -"%i" , (uint8_t ) metadata_type); +snprintf (metadata_type_str,sizeof (metadata_type_str), +"%i" , (uint8_t ) metadata_type);struct env_set *es =env_set_create (NULL );setenv_str (es,"script_type" ,"tls-crypt-v2-verify" );setenv_str (es,"metadata_type" , metadata_type_str);
src/openvpn/tun.c +34 -34
164 lines not on this page · raw message
src/openvpn/win32.c +5 -20
@@ -885,8 +885,8 @@char force_path[256 ];char *sysroot =get_win_sys_path (); -if (!openvpn_snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , - sysroot, sysroot, sysroot)) +if (!snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , + sysroot, sysroot, sysroot)) {msg (M_WARN ,"env_block: default path truncated to %s" , force_path); }
@@ -1483,26 +1483,11 @@ }bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vswprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =L'\0' ; - } -return (len >=0 && len < size); -} - -bool get_openvpn_reg_value (const WCHAR *key,WCHAR *value,DWORD size) {WCHAR reg_path[256 ];HKEY hkey; -openvpn_swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME ); +swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME );LONG status =RegOpenKeyExW (HKEY_LOCAL_MACHINE , reg_path,0 ,KEY_READ , &hkey);if (status !=ERROR_SUCCESS )
@@ -1528,7 +1513,7 @@/* if we cannot find installation path from the registry, * use Windows directory as a fallback */ -openvpn_swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); +swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); }if ((install_path[wcslen (install_path) -1 ]) ==L'\\' )
@@ -1553,7 +1538,7 @@if (size ==0 ) {WCHAR val[MAX_PATH ] = {0 }; -openvpn_swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value); +swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value);_wputenv_s (ossl_env[i].name, val); } }
src/openvpn/win32.h +0 -8
@@ -319,14 +319,6 @@int openvpn_execve (const struct argv *a,const struct env_set *es,const unsigned int flags); -/* -* openvpn_swprintf() is currently only used by Windows code paths -* and when enabled for all platforms it will currently break older -* OpenBSD versions lacking vswprintf(3) support in their libc. -*/ -bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -/* Sleep that can be interrupted by signals and exit event */ void win32_sleep (const int n);
src/openvpn/xkey_helper.c +5 -5
@@ -205,7 +205,7 @@ }else { -openvpn_snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); } }else if (!strcmp (alg.keytype,"ED448" ) || !strcmp (alg.keytype,"ED25519" ))
@@ -229,8 +229,8 @@/* For undigested message, add hashalg=digest parameter */ else { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , -"RSA_PKCS1_PADDING" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , +"RSA_PKCS1_PADDING" , alg.mdname); } } else if (!strcmp(alg.padmode, "none") && (flags & MF_EXTERNAL_KEY_NOPADDING)
@@ -240,8 +240,8 @@ }else if (!strcmp (alg.padmode,"pss" ) && (flags &MF_EXTERNAL_KEY_PSSPAD )) { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , -"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , +"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); }else {
src/openvpnserv/common.c +11 -41
102 lines not on this page · raw message
src/openvpnserv/interactive.c +30 -27
162 lines not on this page · raw message
src/openvpnserv/service.h +0 -6
@@ -81,12 +81,6 @@ VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv); -BOOL openvpn_vsntprintf (LPTSTR str,size_t size,LPCTSTR format,va_list arglist); - -BOOL openvpn_sntprintf (LPTSTR str,size_t size,LPCTSTR format, ...); - -BOOL openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -DWORD GetOpenvpnSettings (settings_t *s);BOOL ReportStatusToSCMgr (SERVICE_STATUS_HANDLE service,SERVICE_STATUS *status);
src/openvpnserv/validate.c +1 -1
@@ -68,7 +68,7 @@/* convert fname to full path */ if (PathIsRelativeW (fname) ) { -openvpn_swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); +swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); config_file = tmp; }else
tests/unit_tests/openvpn/test_buffer.c +51 -0
63 lines not on this page · raw message
tests/unit_tests/openvpn/test_cryptoapi.c +5 -5
@@ -271,7 +271,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); ctx =find_certificate_in_store (select_string, user_store);if (ctx) {
@@ -304,7 +304,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); +snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the common name. But the returned cert may not exactly match
@@ -337,7 +337,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); +snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the issuer. But the returned cert may not exactly match
@@ -411,7 +411,7 @@ {continue ; } -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (Load_CryptoAPI_certificate (select_string, &x509, &privkey) !=1 ) {fail_msg ("Load_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
@@ -446,7 +446,7 @@SSL_CTX *ssl_ctx =SSL_CTX_new_ex (tls_libctx,NULL ,SSLv23_client_method ());assert_non_null (ssl_ctx); -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (!SSL_CTX_use_CryptoAPI_certificate (ssl_ctx, select_string)) {fail_msg ("SSL_CTX_use_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
tests/unit_tests/openvpn/test_pkcs11.c +3 -3
@@ -161,7 +161,7 @@ }else if (flags &GET_USER_PASS_PASSWORD_ONLY ) { -openvpn_snprintf (up->password,sizeof (up->password),"%s" ,PIN ); +snprintf (up->password,sizeof (up->password),"%s" ,PIN ); }else {
@@ -204,8 +204,8 @@ {fail_msg ("make tmpfile using template <%s> failed (error = %d)" , softhsm2_conf_path, errno); } -openvpn_snprintf (config,sizeof (config),"directories.tokendir=%s/" , - softhsm2_tokens_path); +snprintf (config,sizeof (config),"directories.tokendir=%s/" , + softhsm2_tokens_path);assert_int_equal (write (fd, config,strlen (config)),strlen (config));close (fd);
Signature · 19 lines
To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=email To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac Gerrit-Change-Number: 547 Gerrit-PatchSet: 3 Gerrit-Owner: plaisthos <[email protected]...> Gerrit-Reviewer: cron2 <[email protected]...> Gerrit-Reviewer: flichtenheld <[email protected]...> Gerrit-Reviewer: ordex <[email protected]...> Gerrit-Reviewer: plaisthos <[email protected]...> Gerrit-CC: openvpn-devel <[email protected]> Gerrit-Attention: plaisthos <[email protected]...> Gerrit-Attention: cron2 <[email protected]...> Gerrit-Attention: flichtenheld <[email protected]...> Gerrit-Attention: ordex <[email protected]...> Gerrit-MessageType: newpatchset
Attention is currently required from: cron2, flichtenheld, ordex, plaisthos.
Hello cron2, flichtenheld, ordex,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
to look at the new patch set (#4).
Change subject: Remove openvpn_snprintf and similar functions
......................................................................
Remove openvpn_snprintf and similar functions
Old Microsoft versions did strange behaviour but according to the newly added unit test and
https://stackoverflow.com/questions/7706936/is-snprintf-always-null-terminating
this is now standard conforming and we can use the normal snprintf method.
Microsoft own documentation to swprintf also says you nowadays need to define _CRT_NON_CONFORMING_SWPRINTFS to get to non-standard behaviour.
---
M src/openvpn/buffer.c
M src/openvpn/buffer.h
M src/openvpn/crypto.c
M src/openvpn/crypto_mbedtls.c
M src/openvpn/dns.c
M src/openvpn/env_set.c
M src/openvpn/error.c
M src/openvpn/init.c
M src/openvpn/manage.c
M src/openvpn/options.c
M src/openvpn/pkcs11.c
M src/openvpn/platform.c
M src/openvpn/plugin.c
M src/openvpn/pool.c
M src/openvpn/proxy.c
M src/openvpn/ps.c
M src/openvpn/route.c
M src/openvpn/run_command.h
M src/openvpn/socket.c
M src/openvpn/socks.c
M src/openvpn/ssl_mbedtls.c
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_openssl.c
M src/openvpn/ssl_verify.c
M src/openvpn/ssl_verify_mbedtls.c
M src/openvpn/ssl_verify_openssl.c
M src/openvpn/tls_crypt.c
M src/openvpn/tun.c
M src/openvpn/win32.c
M src/openvpn/win32.h
M src/openvpn/xkey_helper.c
M src/openvpnserv/common.c
M src/openvpnserv/interactive.c
M src/openvpnserv/service.h
M src/openvpnserv/validate.c
M tests/unit_tests/openvpn/test_buffer.c
M tests/unit_tests/openvpn/test_cryptoapi.c
M tests/unit_tests/openvpn/test_pkcs11.c
38 files changed, 291 insertions(+), 333 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/47/547/4
src/openvpn/buffer.c +0 -26
@@ -279,32 +279,6 @@return ret; } - -/* -* This is necessary due to certain buggy implementations of snprintf, -* that don't guarantee null termination for size > 0. -* -* Return false on overflow. -* -* This functionality is duplicated in src/openvpnserv/common.c -* Any modifications here should be done to the other place as well. -*/ - -bool -openvpn_snprintf (char *str,size_t size,const char *format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vsnprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =0 ; - } -return (len >=0 && len < size); -} -/* * write a string to the end of a buffer that was * truncated by buf_printf
src/openvpn/buffer.h +0 -13
@@ -448,19 +448,6 @@*/ bool buf_puts (struct buffer *buf,const char *str); -/* -* Like snprintf but guarantees null termination for size > 0 -*/ -bool openvpn_snprintf(char *str, size_t size, const char *format, ...) -#ifdef __GNUC__ -#if __USE_MINGW_ANSI_STDIO -__attribute__ ((format(gnu_printf, 3, 4))) -#else -__attribute__ ((format(__printf__, 3, 4))) -#endif -#endif -; -/* * remove/add trailing characters
src/openvpn/crypto.c +2 -2
@@ -874,11 +874,11 @@key_direction_state_init (&kds, key_direction); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name);init_key_ctx (&ctx->encrypt, &key2->keys[kds.out_key], kt,OPENVPN_OP_ENCRYPT , log_prefix); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name);init_key_ctx (&ctx->decrypt, &key2->keys[kds.in_key], kt,OPENVPN_OP_DECRYPT , log_prefix);
src/openvpn/crypto_mbedtls.c +5 -5
@@ -128,7 +128,7 @@ {char prefix[256 ]; -if (!openvpn_snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) +if (!snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) {return mbed_log_err (flags, errval, func); }
@@ -239,11 +239,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) {return false; }
@@ -278,11 +278,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----" , name)) {return false; }
src/openvpn/dns.c +2 -2
@@ -349,11 +349,11 @@if (j <0 ) { - name_ok =openvpn_snprintf (name,sizeof (name), format, i); + name_ok =snprintf (name,sizeof (name), format, i); }else { - name_ok =openvpn_snprintf (name,sizeof (name), format, i, j); + name_ok =snprintf (name,sizeof (name), format, i, j); }if (!name_ok)
src/openvpn/env_set.c +4 -4
@@ -259,7 +259,7 @@ setenv_counter(struct env_set *es, const char *name, counter_type value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf), counter_format, value); +snprintf (buf,sizeof (buf), counter_format, value);setenv_str (es, name, buf); }
@@ -267,7 +267,7 @@ setenv_int(struct env_set *es, const char *name, int value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%d" , value); +snprintf (buf,sizeof (buf),"%d" , value);setenv_str (es, name, buf); }
@@ -275,7 +275,7 @@ setenv_long_long(struct env_set *es, const char *name, long long value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value); +snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value);setenv_str (es, name, buf); }
@@ -310,7 +310,7 @@strcpy (tmpname, name);while (NULL !=env_set_get (es, tmpname) && counter <1000 ) { -ASSERT (openvpn_snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); +ASSERT (snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); counter++; }if (counter <1000 )
src/openvpn/error.c +7 -7
@@ -274,14 +274,14 @@if ((flags &M_ERRNO ) && e) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , - m1,openvpn_strerror (e, crt_error, &gc), e); +snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , + m1,openvpn_strerror (e, crt_error, &gc), e);SWAP ; }if (flags &M_OPTERR ) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1); +snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1);SWAP ; }
@@ -321,10 +321,10 @@const struct virtual_output *vo =msg_get_virtual_output ();if (vo) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , - prefix, - prefix_sep, - m1); +snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , + prefix, + prefix_sep, + m1);virtual_output_print (vo, flags, m2); } }
src/openvpn/init.c +1 -1
@@ -359,7 +359,7 @@char *out =malloc (len);check_malloc_return (out); -openvpn_snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); +snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); *remote = out; }else
src/openvpn/manage.c +4 -4
@@ -515,8 +515,8 @@char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); -openvpn_snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes); +snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); +snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes);msg (M_CLIENT ,">BYTECOUNT:%s,%s" , in, out); }
@@ -528,8 +528,8 @@char in[32 ];char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, *bytes_in_total); -openvpn_snprintf (out,sizeof (out), counter_format, *bytes_out_total); +snprintf (in,sizeof (in), counter_format, *bytes_in_total); +snprintf (out,sizeof (out), counter_format, *bytes_out_total);msg (M_CLIENT ,">BYTECOUNT_CLI:%lu,%s,%s" , mdac->cid, in, out); mdac->bytecount_last_update = now; }
src/openvpn/options.c +4 -4
@@ -1427,7 +1427,7 @@for (int i =1 ; i <= opt_max; ++i) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , i); +snprintf (name,sizeof (name),"foreign_option_%d" , i);const char *env_str =env_set_get (es, name);const char *value =strchr (env_str,'=' ) +1 ;
@@ -1482,7 +1482,7 @@while (o->foreign_option_index < opt_max) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--); +snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--);setenv_del (es, name); } }
@@ -5674,8 +5674,8 @@#ifndef ENABLE_SMALL {char script_name[100 ]; -openvpn_snprintf (script_name,sizeof (script_name), -"--%s script" , type); +snprintf (script_name,sizeof (script_name), +"--%s script" , type);if (check_cmd_access (*script, script_name, (in_chroot ? options->chroot_dir :NULL ))) {
src/openvpn/pkcs11.c +3 -3
@@ -201,7 +201,7 @@CLEAR (token_resp); token_resp.defined = false; token_resp.nocache = true; - openvpn_snprintf( + snprintf( token_resp.username, sizeof(token_resp.username), "Please insert %s token",
@@ -245,7 +245,7 @@ASSERT (token!=NULL ); -openvpn_snprintf (prompt,sizeof (prompt),"%s token" , token->label); +snprintf (prompt,sizeof (prompt),"%s token" , token->label); token_pass.defined = false; token_pass.nocache = true;
@@ -719,7 +719,7 @@ id_resp.defined = false; id_resp.nocache = true; -openvpn_snprintf ( +snprintf ( id_resp.username,sizeof (id_resp.username), "Please specify PKCS#11 id to use"
src/openvpn/platform.c +3 -3
@@ -564,9 +564,9 @@ { ++attempts; -if (!openvpn_snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, - prefix, (unsigned long )get_random (), - (unsigned long )get_random ())) +if (!snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, + prefix, (unsigned long )get_random (), + (unsigned long )get_random ())) {msg (M_WARN ,"ERROR: temporary filename too long" );return NULL ;
src/openvpn/plugin.c +2 -2
@@ -260,7 +260,7 @@ {char full[PATH_MAX ]; -openvpn_snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); +snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); p->handle =dlopen (full,RTLD_NOW ); } else
@@ -409,7 +409,7 @@gc_init (&gc); msg_fmt =gc_malloc (ERR_BUF_SIZE , false, &gc); -openvpn_snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format); +snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format);x_msg_va (msg_flags, msg_fmt, arglist);gc_free (&gc);
src/openvpn/pool.c +1 -1
@@ -766,7 +766,7 @@ifconfig_pool_handle h;in_addr_t local, remote;char buf[256 ]; -openvpn_snprintf (buf,sizeof (buf),"common-name-%d" , i); +snprintf (buf,sizeof (buf),"common-name-%d" , i);#ifdef DUP_CN cn =NULL ;#else
src/openvpn/proxy.c +44 -43
185 lines not on this page · raw message
src/openvpn/ps.c +1 -1
@@ -354,7 +354,7 @@ fnlen =strlen (journal_dir) +strlen (t) +2 ; jfn = (char *)malloc (fnlen);check_malloc_return (jfn); -openvpn_snprintf (jfn, fnlen,"%s/%s" , journal_dir, t); +snprintf (jfn, fnlen,"%s/%s" , journal_dir, t);dmsg (D_PS_PROXY_DEBUG ,"PORT SHARE PROXY: client origin %s -> %s" , jfn, f); fd =platform_open (jfn,O_CREAT |O_TRUNC |O_WRONLY ,S_IRUSR |S_IWUSR |S_IRGRP );if (fd !=-1 )
src/openvpn/route.c +3 -3
@@ -1621,11 +1621,11 @@if (rgi) { -openvpn_snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); +snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); }else { -openvpn_snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); +snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); }bool ret =management_android_control (management,"ROUTE" , out); status = ret ?RTA_SUCCESS :RTA_ERROR ;
@@ -2000,7 +2000,7 @@#elif defined (TARGET_ANDROID )char out[64 ]; -openvpn_snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); +snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); status =management_android_control (management,"ROUTE6" , out);
src/openvpn/run_command.h +2 -2
@@ -66,8 +66,8 @@ {char msg[256 ]; -openvpn_snprintf (msg,sizeof (msg), -"WARNING: Failed running command (%s)" , hook); +snprintf (msg,sizeof (msg), +"WARNING: Failed running command (%s)" , hook);return openvpn_execve_check (a, es, flags |S_SCRIPT , msg); }
src/openvpn/socket.c +6 -6
@@ -2983,11 +2983,11 @@case AF_INET :if (flags &SA_IP_PORT ) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); }inet_ntop (AF_INET , &addr->addr.in4.sin_addr, buf,sizeof (buf));
@@ -2995,7 +2995,7 @@if ((flags &SA_IP_PORT ) && addr->addr.in4.sin_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in4.sin_port)); }break ;
@@ -3006,19 +3006,19 @@struct in_addr ia;memcpy (&ia.s_addr, &addr->addr.in6.sin6_addr.s6_addr[12 ],sizeof (ia.s_addr)); -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix);inet_ntop (AF_INET , &ia, buf,sizeof (buf)); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix);inet_ntop (AF_INET6 , &addr->addr.in6.sin6_addr, buf,sizeof (buf)); }setenv_str (es, name_buf, buf);if ((flags &SA_IP_PORT ) && addr->addr.in6.sin6_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in6.sin6_port)); }break ;
src/openvpn/socks.c +4 -3
@@ -109,9 +109,10 @@ "Authentication not possible."); goto cleanup; } -int sret =openvpn_snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , - (int )strlen (creds.username), creds.username, - (int )strlen (creds.password), creds.password); + +int sret =snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , + (int )strlen (creds.username), creds.username, + (int )strlen (creds.password), creds.password);ASSERT (sret <=sizeof (to_send)); size =send (sd, to_send,strlen (to_send),MSG_NOSIGNAL );
src/openvpn/ssl_mbedtls.c +6 -6
@@ -1531,16 +1531,16 @@char s2[256 ]; s1[0 ] = s2[0 ] =0 ; -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s" , - prefix, -mbedtls_ssl_get_version (ks_ssl->ctx), -mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s" , + prefix, +mbedtls_ssl_get_version (ks_ssl->ctx), +mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); cert =mbedtls_ssl_get_peer_cert (ks_ssl->ctx);if (cert !=NULL ) { -openvpn_snprintf (s2,sizeof (s2),", %u bit key" , - (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); +snprintf (s2,sizeof (s2),", %u bit key" , + (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); }msg (D_HANDSHAKE ,"%s%s" , s1, s2);
src/openvpn/ssl_ncp.c +2 -2
@@ -198,8 +198,8 @@size_t newlen =strlen (o->ncp_ciphers) +1 +strlen (ciphername) +1 ;char *ncp_ciphers =gc_malloc (newlen, false, &o->gc); -ASSERT (openvpn_snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, - ciphername)); +ASSERT (snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, + ciphername)); o->ncp_ciphers = ncp_ciphers; }
src/openvpn/ssl_openssl.c +16 -16
@@ -1774,7 +1774,7 @@if (!biofp) {char fn[256 ]; -openvpn_snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); +snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); biofp =fopen (fn,"w" );ASSERT (biofp); biofp_last_open =time (NULL );
@@ -2116,8 +2116,8 @@#endif /* if OPENSSL_VERSION_NUMBER < 0x30000000L */ } -openvpn_snprintf (buf, buflen,"%d bits %s%s" , -EVP_PKEY_bits (pkey), type, curve); +snprintf (buf, buflen,"%d bits %s%s" , +EVP_PKEY_bits (pkey), type, curve); }/**
@@ -2137,12 +2137,12 @@int signature_nid =X509_get_signature_nid (cert);if (signature_nid !=0 ) { -openvpn_snprintf (sig,sizeof (sig),", signature: %s" , -OBJ_nid2sn (signature_nid)); +snprintf (sig,sizeof (sig),", signature: %s" , +OBJ_nid2sn (signature_nid)); } -openvpn_snprintf (buf, buflen,", peer certificate: %s%s" , - pkeybuf, sig); +snprintf (buf, buflen,", peer certificate: %s%s" , + pkeybuf, sig);EVP_PKEY_free (pkey); }
@@ -2160,8 +2160,8 @@char pkeybuf[128 ] = {0 };print_pkey_details (pkey, pkeybuf,sizeof (pkeybuf)); -openvpn_snprintf (buf, buflen,", peer temporary key: %s" , - pkeybuf); +snprintf (buf, buflen,", peer temporary key: %s" , + pkeybuf);EVP_PKEY_free (pkey); }
@@ -2238,8 +2238,8 @@return ; } -openvpn_snprintf (buf, buflen,", peer signing digest/type: %s %s" , - peer_sig, peer_sig_type); +snprintf (buf, buflen,", peer signing digest/type: %s %s" , + peer_sig, peer_sig_type); }
@@ -2262,11 +2262,11 @@ s1[0 ] = s2[0 ] = s3[0 ] = s4[0 ] =0 ; ciph =SSL_get_current_cipher (ks_ssl->ssl); -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , - prefix, -SSL_get_version (ks_ssl->ssl), -SSL_CIPHER_get_version (ciph), -SSL_CIPHER_get_name (ciph)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , + prefix, +SSL_get_version (ks_ssl->ssl), +SSL_CIPHER_get_version (ciph), +SSL_CIPHER_get_name (ciph));X509 *cert =SSL_get_peer_certificate (ks_ssl->ssl);if (cert)
src/openvpn/ssl_verify.c +11 -11
@@ -421,12 +421,12 @@ }/* export subject name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth);setenv_str (es, envname, subject);#if 0 /* export common name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth);setenv_str (es, envname, common_name);#endif
@@ -435,24 +435,24 @@struct buffer sha1 =x509_get_sha1_fingerprint (peer_cert, &gc);struct buffer sha256 =x509_get_sha256_fingerprint (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha1),BLEN (&sha1),0 ,1 ,":" , &gc)); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , - cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , + cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha256),BLEN (&sha256),0 ,1 ,":" , &gc)); }/* export serial number as environmental variable */ serial =backend_x509_get_serial (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth);setenv_str (es, envname, serial);/* export serial number in hex as environmental variable */ serial =backend_x509_get_serial_hex (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth);setenv_str (es, envname, serial);gc_free (&gc);
@@ -569,7 +569,7 @@ goto cleanup; } -if (!openvpn_snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) +if (!snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) {msg (D_HANDSHAKE ,"VERIFY CRL: filename overflow" ); goto cleanup;
@@ -938,9 +938,9 @@if (!check_auth_pending_method (multi->peer_info, pending_method)) {char buf[128 ]; -openvpn_snprintf (buf,sizeof (buf), -"Authentication failed, required pending auth " -"method '%s' not supported" , pending_method); +snprintf (buf,sizeof (buf), +"Authentication failed, required pending auth " +"method '%s' not supported" , pending_method);auth_set_client_reason (multi, buf);msg (M_INFO ,"Client does not supported auth pending method " "'%s'" , pending_method);
src/openvpn/ssl_verify_mbedtls.c +7 -7
@@ -86,8 +86,8 @@char *serial =backend_x509_get_serial (cert, &gc); ret =mbedtls_x509_crt_verify_info (errstr,sizeof (errstr)-1 ,"" , *flags); -if (ret <=0 && !openvpn_snprintf (errstr,sizeof (errstr), -"Could not retrieve error string, flags=%" PRIx32, *flags)) +if (ret <=0 && !snprintf (errstr,sizeof (errstr), +"Could not retrieve error string, flags=%" PRIx32, *flags)) { errstr[0 ] ='\0' ; }
@@ -307,7 +307,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -431,13 +431,13 @@if (0 ==mbedtls_oid_get_attr_short_name (&name->oid, &shortname) ) { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , - cert_depth, shortname); +snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , + cert_depth, shortname); }else { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , - cert_depth); +snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , + cert_depth); }for (i =0 ; i < name->val.len; i++)
src/openvpn/ssl_verify_openssl.c +4 -4
@@ -279,7 +279,7 @@gc_free (&gc);return FAILURE ; } -openvpn_snprintf (common_name, cn_len,"0x%s" , serial); +snprintf (common_name, cn_len,"0x%s" , serial);gc_free (&gc); }else
@@ -454,7 +454,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -597,8 +597,8 @@ name_expand_size =64 +strlen (objbuf); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, - objbuf); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, + objbuf);string_mod (name_expand,CC_PRINT ,CC_CRLF ,'_' );string_mod ((char *)buf,CC_PRINT ,CC_CRLF ,'_' );setenv_str_incr (es, name_expand, (char *)buf);
src/openvpn/tls_crypt.c +2 -2
@@ -574,8 +574,8 @@ }char metadata_type_str[4 ] = {0 };/* Max value: 255 */ -openvpn_snprintf (metadata_type_str,sizeof (metadata_type_str), -"%i" , (uint8_t ) metadata_type); +snprintf (metadata_type_str,sizeof (metadata_type_str), +"%i" , (uint8_t ) metadata_type);struct env_set *es =env_set_create (NULL );setenv_str (es,"script_type" ,"tls-crypt-v2-verify" );setenv_str (es,"metadata_type" , metadata_type_str);
src/openvpn/tun.c +34 -34
164 lines not on this page · raw message
src/openvpn/win32.c +5 -20
@@ -885,8 +885,8 @@char force_path[256 ];char *sysroot =get_win_sys_path (); -if (!openvpn_snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , - sysroot, sysroot, sysroot)) +if (!snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , + sysroot, sysroot, sysroot)) {msg (M_WARN ,"env_block: default path truncated to %s" , force_path); }
@@ -1483,26 +1483,11 @@ }bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vswprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =L'\0' ; - } -return (len >=0 && len < size); -} - -bool get_openvpn_reg_value (const WCHAR *key,WCHAR *value,DWORD size) {WCHAR reg_path[256 ];HKEY hkey; -openvpn_swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME ); +swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME );LONG status =RegOpenKeyExW (HKEY_LOCAL_MACHINE , reg_path,0 ,KEY_READ , &hkey);if (status !=ERROR_SUCCESS )
@@ -1528,7 +1513,7 @@/* if we cannot find installation path from the registry, * use Windows directory as a fallback */ -openvpn_swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); +swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); }if ((install_path[wcslen (install_path) -1 ]) ==L'\\' )
@@ -1553,7 +1538,7 @@if (size ==0 ) {WCHAR val[MAX_PATH ] = {0 }; -openvpn_swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value); +swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value);_wputenv_s (ossl_env[i].name, val); } }
src/openvpn/win32.h +0 -8
@@ -319,14 +319,6 @@int openvpn_execve (const struct argv *a,const struct env_set *es,const unsigned int flags); -/* -* openvpn_swprintf() is currently only used by Windows code paths -* and when enabled for all platforms it will currently break older -* OpenBSD versions lacking vswprintf(3) support in their libc. -*/ -bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -/* Sleep that can be interrupted by signals and exit event */ void win32_sleep (const int n);
src/openvpn/xkey_helper.c +5 -5
@@ -205,7 +205,7 @@ }else { -openvpn_snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); } }else if (!strcmp (alg.keytype,"ED448" ) || !strcmp (alg.keytype,"ED25519" ))
@@ -229,8 +229,8 @@/* For undigested message, add hashalg=digest parameter */ else { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , -"RSA_PKCS1_PADDING" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , +"RSA_PKCS1_PADDING" , alg.mdname); } } else if (!strcmp(alg.padmode, "none") && (flags & MF_EXTERNAL_KEY_NOPADDING)
@@ -240,8 +240,8 @@ }else if (!strcmp (alg.padmode,"pss" ) && (flags &MF_EXTERNAL_KEY_PSSPAD )) { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , -"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , +"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); }else {
src/openvpnserv/common.c +11 -41
102 lines not on this page · raw message
src/openvpnserv/interactive.c +30 -27
162 lines not on this page · raw message
src/openvpnserv/service.h +0 -6
@@ -81,12 +81,6 @@ VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv); -BOOL openvpn_vsntprintf (LPTSTR str,size_t size,LPCTSTR format,va_list arglist); - -BOOL openvpn_sntprintf (LPTSTR str,size_t size,LPCTSTR format, ...); - -BOOL openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -DWORD GetOpenvpnSettings (settings_t *s);BOOL ReportStatusToSCMgr (SERVICE_STATUS_HANDLE service,SERVICE_STATUS *status);
src/openvpnserv/validate.c +1 -1
@@ -68,7 +68,7 @@/* convert fname to full path */ if (PathIsRelativeW (fname) ) { -openvpn_swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); +swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); config_file = tmp; }else
tests/unit_tests/openvpn/test_buffer.c +51 -0
63 lines not on this page · raw message
tests/unit_tests/openvpn/test_cryptoapi.c +5 -5
@@ -271,7 +271,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); ctx =find_certificate_in_store (select_string, user_store);if (ctx) {
@@ -304,7 +304,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); +snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the common name. But the returned cert may not exactly match
@@ -337,7 +337,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); +snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the issuer. But the returned cert may not exactly match
@@ -411,7 +411,7 @@ {continue ; } -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (Load_CryptoAPI_certificate (select_string, &x509, &privkey) !=1 ) {fail_msg ("Load_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
@@ -446,7 +446,7 @@SSL_CTX *ssl_ctx =SSL_CTX_new_ex (tls_libctx,NULL ,SSLv23_client_method ());assert_non_null (ssl_ctx); -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (!SSL_CTX_use_CryptoAPI_certificate (ssl_ctx, select_string)) {fail_msg ("SSL_CTX_use_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
tests/unit_tests/openvpn/test_pkcs11.c +3 -3
@@ -161,7 +161,7 @@ }else if (flags &GET_USER_PASS_PASSWORD_ONLY ) { -openvpn_snprintf (up->password,sizeof (up->password),"%s" ,PIN ); +snprintf (up->password,sizeof (up->password),"%s" ,PIN ); }else {
@@ -204,8 +204,8 @@ {fail_msg ("make tmpfile using template <%s> failed (error = %d)" , softhsm2_conf_path, errno); } -openvpn_snprintf (config,sizeof (config),"directories.tokendir=%s/" , - softhsm2_tokens_path); +snprintf (config,sizeof (config),"directories.tokendir=%s/" , + softhsm2_tokens_path);assert_int_equal (write (fd, config,strlen (config)),strlen (config));close (fd);
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac
Gerrit-Change-Number: 547
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: cron2, flichtenheld, ordex.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/547?usp=email )
Change subject: Remove openvpn_snprintf and similar functions
......................................................................
Patch Set 3:
(2 comments)
File src/openvpnserv/interactive.c:
http://gerrit.openvpn.net/c/openvpn/+/547/comment/a795b02d_09b66782 :
PS2, Line 2007: sud.options, svc_pipe);
Quoted 1 line
This makes GHA msbuild build fails now, with […]
Done
File tests/unit_tests/openvpn/test_buffer.c:
http://gerrit.openvpn.net/c/openvpn/+/547/comment/f9701207_7c4b904b :
PS2, Line 369: * for this unit test. We know that are doing this that are truncated
Quoted 1 line
I think there is some typ0 here. […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac
Gerrit-Change-Number: 547
Gerrit-PatchSet: 3
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Thu, 02 May 2024 17:44:31 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: cron2, ordex, plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/547?usp=email )
Change subject: Remove openvpn_snprintf and similar functions
......................................................................
Patch Set 4: Code-Review-1
(2 comments)
File src/openvpn/proxy.c:
http://gerrit.openvpn.net/c/openvpn/+/547/comment/44a4b5a4_ab3ddf72 :
PS4, Line 966:
Why this spurious change?
File tests/unit_tests/openvpn/test_buffer.c:
http://gerrit.openvpn.net/c/openvpn/+/547/comment/9f564a6c_9986bda3 :
PS4, Line 401: #pragma GCC diagnostic pop
Should that be "clang" instead of "GCC"?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac
Gerrit-Change-Number: 547
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Fri, 03 May 2024 15:49:05 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld, ordex.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/547?usp=email )
Change subject: Remove openvpn_snprintf and similar functions
......................................................................
Patch Set 4:
(2 comments)
File src/openvpn/proxy.c:
http://gerrit.openvpn.net/c/openvpn/+/547/comment/aac61c1c_be6f9120 :
PS4, Line 966:
Quoted 1 line
Why this spurious change?
What do you mean with spurious? It changes openvpn_snprintf to snprintf
File tests/unit_tests/openvpn/test_buffer.c:
http://gerrit.openvpn.net/c/openvpn/+/547/comment/e325e787_1f2bea7f :
PS4, Line 401: #pragma GCC diagnostic pop
Quoted 1 line
Should that be "clang" instead of "GCC"?
yeah, although it seems work this way as well. Will fix.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac
Gerrit-Change-Number: 547
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Fri, 03 May 2024 16:44:39 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld, ordex.
Hello cron2, flichtenheld, ordex,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
to look at the new patch set (#5).
The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld
Change subject: Remove openvpn_snprintf and similar functions
......................................................................
Remove openvpn_snprintf and similar functions
Old Microsoft versions did strange behaviour but according to the newly added unit test and
https://stackoverflow.com/questions/7706936/is-snprintf-always-null-terminating
this is now standard conforming and we can use the normal snprintf method.
Microsoft own documentation to swprintf also says you nowadays need to define _CRT_NON_CONFORMING_SWPRINTFS to get to non-standard behaviour.
---
M src/openvpn/buffer.c
M src/openvpn/buffer.h
M src/openvpn/crypto.c
M src/openvpn/crypto_mbedtls.c
M src/openvpn/dns.c
M src/openvpn/env_set.c
M src/openvpn/error.c
M src/openvpn/init.c
M src/openvpn/manage.c
M src/openvpn/options.c
M src/openvpn/pkcs11.c
M src/openvpn/platform.c
M src/openvpn/plugin.c
M src/openvpn/pool.c
M src/openvpn/proxy.c
M src/openvpn/ps.c
M src/openvpn/route.c
M src/openvpn/run_command.h
M src/openvpn/socket.c
M src/openvpn/socks.c
M src/openvpn/ssl_mbedtls.c
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_openssl.c
M src/openvpn/ssl_verify.c
M src/openvpn/ssl_verify_mbedtls.c
M src/openvpn/ssl_verify_openssl.c
M src/openvpn/tls_crypt.c
M src/openvpn/tun.c
M src/openvpn/win32.c
M src/openvpn/win32.h
M src/openvpn/xkey_helper.c
M src/openvpnserv/common.c
M src/openvpnserv/interactive.c
M src/openvpnserv/service.h
M src/openvpnserv/validate.c
M tests/unit_tests/openvpn/test_buffer.c
M tests/unit_tests/openvpn/test_cryptoapi.c
M tests/unit_tests/openvpn/test_pkcs11.c
38 files changed, 291 insertions(+), 333 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/47/547/5
src/openvpn/buffer.c +0 -26
@@ -279,32 +279,6 @@return ret; } - -/* -* This is necessary due to certain buggy implementations of snprintf, -* that don't guarantee null termination for size > 0. -* -* Return false on overflow. -* -* This functionality is duplicated in src/openvpnserv/common.c -* Any modifications here should be done to the other place as well. -*/ - -bool -openvpn_snprintf (char *str,size_t size,const char *format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vsnprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =0 ; - } -return (len >=0 && len < size); -} -/* * write a string to the end of a buffer that was * truncated by buf_printf
src/openvpn/buffer.h +0 -13
@@ -448,19 +448,6 @@*/ bool buf_puts (struct buffer *buf,const char *str); -/* -* Like snprintf but guarantees null termination for size > 0 -*/ -bool openvpn_snprintf(char *str, size_t size, const char *format, ...) -#ifdef __GNUC__ -#if __USE_MINGW_ANSI_STDIO -__attribute__ ((format(gnu_printf, 3, 4))) -#else -__attribute__ ((format(__printf__, 3, 4))) -#endif -#endif -; -/* * remove/add trailing characters
src/openvpn/crypto.c +2 -2
@@ -874,11 +874,11 @@key_direction_state_init (&kds, key_direction); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name);init_key_ctx (&ctx->encrypt, &key2->keys[kds.out_key], kt,OPENVPN_OP_ENCRYPT , log_prefix); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name);init_key_ctx (&ctx->decrypt, &key2->keys[kds.in_key], kt,OPENVPN_OP_DECRYPT , log_prefix);
src/openvpn/crypto_mbedtls.c +5 -5
@@ -128,7 +128,7 @@ {char prefix[256 ]; -if (!openvpn_snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) +if (!snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) {return mbed_log_err (flags, errval, func); }
@@ -239,11 +239,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) {return false; }
@@ -278,11 +278,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----" , name)) {return false; }
src/openvpn/dns.c +2 -2
@@ -349,11 +349,11 @@if (j <0 ) { - name_ok =openvpn_snprintf (name,sizeof (name), format, i); + name_ok =snprintf (name,sizeof (name), format, i); }else { - name_ok =openvpn_snprintf (name,sizeof (name), format, i, j); + name_ok =snprintf (name,sizeof (name), format, i, j); }if (!name_ok)
src/openvpn/env_set.c +4 -4
@@ -259,7 +259,7 @@ setenv_counter(struct env_set *es, const char *name, counter_type value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf), counter_format, value); +snprintf (buf,sizeof (buf), counter_format, value);setenv_str (es, name, buf); }
@@ -267,7 +267,7 @@ setenv_int(struct env_set *es, const char *name, int value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%d" , value); +snprintf (buf,sizeof (buf),"%d" , value);setenv_str (es, name, buf); }
@@ -275,7 +275,7 @@ setenv_long_long(struct env_set *es, const char *name, long long value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value); +snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value);setenv_str (es, name, buf); }
@@ -310,7 +310,7 @@strcpy (tmpname, name);while (NULL !=env_set_get (es, tmpname) && counter <1000 ) { -ASSERT (openvpn_snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); +ASSERT (snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); counter++; }if (counter <1000 )
src/openvpn/error.c +7 -7
@@ -274,14 +274,14 @@if ((flags &M_ERRNO ) && e) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , - m1,openvpn_strerror (e, crt_error, &gc), e); +snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , + m1,openvpn_strerror (e, crt_error, &gc), e);SWAP ; }if (flags &M_OPTERR ) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1); +snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1);SWAP ; }
@@ -321,10 +321,10 @@const struct virtual_output *vo =msg_get_virtual_output ();if (vo) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , - prefix, - prefix_sep, - m1); +snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , + prefix, + prefix_sep, + m1);virtual_output_print (vo, flags, m2); } }
src/openvpn/init.c +1 -1
@@ -359,7 +359,7 @@char *out =malloc (len);check_malloc_return (out); -openvpn_snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); +snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); *remote = out; }else
src/openvpn/manage.c +4 -4
@@ -515,8 +515,8 @@char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); -openvpn_snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes); +snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); +snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes);msg (M_CLIENT ,">BYTECOUNT:%s,%s" , in, out); }
@@ -528,8 +528,8 @@char in[32 ];char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, *bytes_in_total); -openvpn_snprintf (out,sizeof (out), counter_format, *bytes_out_total); +snprintf (in,sizeof (in), counter_format, *bytes_in_total); +snprintf (out,sizeof (out), counter_format, *bytes_out_total);msg (M_CLIENT ,">BYTECOUNT_CLI:%lu,%s,%s" , mdac->cid, in, out); mdac->bytecount_last_update = now; }
src/openvpn/options.c +4 -4
@@ -1427,7 +1427,7 @@for (int i =1 ; i <= opt_max; ++i) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , i); +snprintf (name,sizeof (name),"foreign_option_%d" , i);const char *env_str =env_set_get (es, name);const char *value =strchr (env_str,'=' ) +1 ;
@@ -1482,7 +1482,7 @@while (o->foreign_option_index < opt_max) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--); +snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--);setenv_del (es, name); } }
@@ -5674,8 +5674,8 @@#ifndef ENABLE_SMALL {char script_name[100 ]; -openvpn_snprintf (script_name,sizeof (script_name), -"--%s script" , type); +snprintf (script_name,sizeof (script_name), +"--%s script" , type);if (check_cmd_access (*script, script_name, (in_chroot ? options->chroot_dir :NULL ))) {
src/openvpn/pkcs11.c +3 -3
@@ -201,7 +201,7 @@CLEAR (token_resp); token_resp.defined = false; token_resp.nocache = true; - openvpn_snprintf( + snprintf( token_resp.username, sizeof(token_resp.username), "Please insert %s token",
@@ -245,7 +245,7 @@ASSERT (token!=NULL ); -openvpn_snprintf (prompt,sizeof (prompt),"%s token" , token->label); +snprintf (prompt,sizeof (prompt),"%s token" , token->label); token_pass.defined = false; token_pass.nocache = true;
@@ -719,7 +719,7 @@ id_resp.defined = false; id_resp.nocache = true; -openvpn_snprintf ( +snprintf ( id_resp.username,sizeof (id_resp.username), "Please specify PKCS#11 id to use"
src/openvpn/platform.c +3 -3
@@ -564,9 +564,9 @@ { ++attempts; -if (!openvpn_snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, - prefix, (unsigned long )get_random (), - (unsigned long )get_random ())) +if (!snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, + prefix, (unsigned long )get_random (), + (unsigned long )get_random ())) {msg (M_WARN ,"ERROR: temporary filename too long" );return NULL ;
src/openvpn/plugin.c +2 -2
@@ -260,7 +260,7 @@ {char full[PATH_MAX ]; -openvpn_snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); +snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); p->handle =dlopen (full,RTLD_NOW ); } else
@@ -409,7 +409,7 @@gc_init (&gc); msg_fmt =gc_malloc (ERR_BUF_SIZE , false, &gc); -openvpn_snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format); +snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format);x_msg_va (msg_flags, msg_fmt, arglist);gc_free (&gc);
src/openvpn/pool.c +1 -1
@@ -766,7 +766,7 @@ifconfig_pool_handle h;in_addr_t local, remote;char buf[256 ]; -openvpn_snprintf (buf,sizeof (buf),"common-name-%d" , i); +snprintf (buf,sizeof (buf),"common-name-%d" , i);#ifdef DUP_CN cn =NULL ;#else
src/openvpn/proxy.c +44 -43
185 lines not on this page · raw message
src/openvpn/ps.c +1 -1
@@ -354,7 +354,7 @@ fnlen =strlen (journal_dir) +strlen (t) +2 ; jfn = (char *)malloc (fnlen);check_malloc_return (jfn); -openvpn_snprintf (jfn, fnlen,"%s/%s" , journal_dir, t); +snprintf (jfn, fnlen,"%s/%s" , journal_dir, t);dmsg (D_PS_PROXY_DEBUG ,"PORT SHARE PROXY: client origin %s -> %s" , jfn, f); fd =platform_open (jfn,O_CREAT |O_TRUNC |O_WRONLY ,S_IRUSR |S_IWUSR |S_IRGRP );if (fd !=-1 )
src/openvpn/route.c +3 -3
@@ -1621,11 +1621,11 @@if (rgi) { -openvpn_snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); +snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); }else { -openvpn_snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); +snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); }bool ret =management_android_control (management,"ROUTE" , out); status = ret ?RTA_SUCCESS :RTA_ERROR ;
@@ -2000,7 +2000,7 @@#elif defined (TARGET_ANDROID )char out[64 ]; -openvpn_snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); +snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); status =management_android_control (management,"ROUTE6" , out);
src/openvpn/run_command.h +2 -2
@@ -66,8 +66,8 @@ {char msg[256 ]; -openvpn_snprintf (msg,sizeof (msg), -"WARNING: Failed running command (%s)" , hook); +snprintf (msg,sizeof (msg), +"WARNING: Failed running command (%s)" , hook);return openvpn_execve_check (a, es, flags |S_SCRIPT , msg); }
src/openvpn/socket.c +6 -6
@@ -2983,11 +2983,11 @@case AF_INET :if (flags &SA_IP_PORT ) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); }inet_ntop (AF_INET , &addr->addr.in4.sin_addr, buf,sizeof (buf));
@@ -2995,7 +2995,7 @@if ((flags &SA_IP_PORT ) && addr->addr.in4.sin_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in4.sin_port)); }break ;
@@ -3006,19 +3006,19 @@struct in_addr ia;memcpy (&ia.s_addr, &addr->addr.in6.sin6_addr.s6_addr[12 ],sizeof (ia.s_addr)); -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix);inet_ntop (AF_INET , &ia, buf,sizeof (buf)); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix);inet_ntop (AF_INET6 , &addr->addr.in6.sin6_addr, buf,sizeof (buf)); }setenv_str (es, name_buf, buf);if ((flags &SA_IP_PORT ) && addr->addr.in6.sin6_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in6.sin6_port)); }break ;
src/openvpn/socks.c +4 -3
@@ -109,9 +109,10 @@ "Authentication not possible."); goto cleanup; } -int sret =openvpn_snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , - (int )strlen (creds.username), creds.username, - (int )strlen (creds.password), creds.password); + +int sret =snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , + (int )strlen (creds.username), creds.username, + (int )strlen (creds.password), creds.password);ASSERT (sret <=sizeof (to_send)); size =send (sd, to_send,strlen (to_send),MSG_NOSIGNAL );
src/openvpn/ssl_mbedtls.c +6 -6
@@ -1531,16 +1531,16 @@char s2[256 ]; s1[0 ] = s2[0 ] =0 ; -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s" , - prefix, -mbedtls_ssl_get_version (ks_ssl->ctx), -mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s" , + prefix, +mbedtls_ssl_get_version (ks_ssl->ctx), +mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); cert =mbedtls_ssl_get_peer_cert (ks_ssl->ctx);if (cert !=NULL ) { -openvpn_snprintf (s2,sizeof (s2),", %u bit key" , - (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); +snprintf (s2,sizeof (s2),", %u bit key" , + (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); }msg (D_HANDSHAKE ,"%s%s" , s1, s2);
src/openvpn/ssl_ncp.c +2 -2
@@ -198,8 +198,8 @@size_t newlen =strlen (o->ncp_ciphers) +1 +strlen (ciphername) +1 ;char *ncp_ciphers =gc_malloc (newlen, false, &o->gc); -ASSERT (openvpn_snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, - ciphername)); +ASSERT (snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, + ciphername)); o->ncp_ciphers = ncp_ciphers; }
src/openvpn/ssl_openssl.c +16 -16
@@ -1774,7 +1774,7 @@if (!biofp) {char fn[256 ]; -openvpn_snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); +snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); biofp =fopen (fn,"w" );ASSERT (biofp); biofp_last_open =time (NULL );
@@ -2116,8 +2116,8 @@#endif /* if OPENSSL_VERSION_NUMBER < 0x30000000L */ } -openvpn_snprintf (buf, buflen,"%d bits %s%s" , -EVP_PKEY_bits (pkey), type, curve); +snprintf (buf, buflen,"%d bits %s%s" , +EVP_PKEY_bits (pkey), type, curve); }/**
@@ -2137,12 +2137,12 @@int signature_nid =X509_get_signature_nid (cert);if (signature_nid !=0 ) { -openvpn_snprintf (sig,sizeof (sig),", signature: %s" , -OBJ_nid2sn (signature_nid)); +snprintf (sig,sizeof (sig),", signature: %s" , +OBJ_nid2sn (signature_nid)); } -openvpn_snprintf (buf, buflen,", peer certificate: %s%s" , - pkeybuf, sig); +snprintf (buf, buflen,", peer certificate: %s%s" , + pkeybuf, sig);EVP_PKEY_free (pkey); }
@@ -2160,8 +2160,8 @@char pkeybuf[128 ] = {0 };print_pkey_details (pkey, pkeybuf,sizeof (pkeybuf)); -openvpn_snprintf (buf, buflen,", peer temporary key: %s" , - pkeybuf); +snprintf (buf, buflen,", peer temporary key: %s" , + pkeybuf);EVP_PKEY_free (pkey); }
@@ -2238,8 +2238,8 @@return ; } -openvpn_snprintf (buf, buflen,", peer signing digest/type: %s %s" , - peer_sig, peer_sig_type); +snprintf (buf, buflen,", peer signing digest/type: %s %s" , + peer_sig, peer_sig_type); }
@@ -2262,11 +2262,11 @@ s1[0 ] = s2[0 ] = s3[0 ] = s4[0 ] =0 ; ciph =SSL_get_current_cipher (ks_ssl->ssl); -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , - prefix, -SSL_get_version (ks_ssl->ssl), -SSL_CIPHER_get_version (ciph), -SSL_CIPHER_get_name (ciph)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , + prefix, +SSL_get_version (ks_ssl->ssl), +SSL_CIPHER_get_version (ciph), +SSL_CIPHER_get_name (ciph));X509 *cert =SSL_get_peer_certificate (ks_ssl->ssl);if (cert)
src/openvpn/ssl_verify.c +11 -11
@@ -421,12 +421,12 @@ }/* export subject name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth);setenv_str (es, envname, subject);#if 0 /* export common name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth);setenv_str (es, envname, common_name);#endif
@@ -435,24 +435,24 @@struct buffer sha1 =x509_get_sha1_fingerprint (peer_cert, &gc);struct buffer sha256 =x509_get_sha256_fingerprint (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha1),BLEN (&sha1),0 ,1 ,":" , &gc)); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , - cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , + cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha256),BLEN (&sha256),0 ,1 ,":" , &gc)); }/* export serial number as environmental variable */ serial =backend_x509_get_serial (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth);setenv_str (es, envname, serial);/* export serial number in hex as environmental variable */ serial =backend_x509_get_serial_hex (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth);setenv_str (es, envname, serial);gc_free (&gc);
@@ -569,7 +569,7 @@ goto cleanup; } -if (!openvpn_snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) +if (!snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) {msg (D_HANDSHAKE ,"VERIFY CRL: filename overflow" ); goto cleanup;
@@ -938,9 +938,9 @@if (!check_auth_pending_method (multi->peer_info, pending_method)) {char buf[128 ]; -openvpn_snprintf (buf,sizeof (buf), -"Authentication failed, required pending auth " -"method '%s' not supported" , pending_method); +snprintf (buf,sizeof (buf), +"Authentication failed, required pending auth " +"method '%s' not supported" , pending_method);auth_set_client_reason (multi, buf);msg (M_INFO ,"Client does not supported auth pending method " "'%s'" , pending_method);
src/openvpn/ssl_verify_mbedtls.c +7 -7
@@ -86,8 +86,8 @@char *serial =backend_x509_get_serial (cert, &gc); ret =mbedtls_x509_crt_verify_info (errstr,sizeof (errstr)-1 ,"" , *flags); -if (ret <=0 && !openvpn_snprintf (errstr,sizeof (errstr), -"Could not retrieve error string, flags=%" PRIx32, *flags)) +if (ret <=0 && !snprintf (errstr,sizeof (errstr), +"Could not retrieve error string, flags=%" PRIx32, *flags)) { errstr[0 ] ='\0' ; }
@@ -307,7 +307,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -431,13 +431,13 @@if (0 ==mbedtls_oid_get_attr_short_name (&name->oid, &shortname) ) { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , - cert_depth, shortname); +snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , + cert_depth, shortname); }else { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , - cert_depth); +snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , + cert_depth); }for (i =0 ; i < name->val.len; i++)
src/openvpn/ssl_verify_openssl.c +4 -4
@@ -279,7 +279,7 @@gc_free (&gc);return FAILURE ; } -openvpn_snprintf (common_name, cn_len,"0x%s" , serial); +snprintf (common_name, cn_len,"0x%s" , serial);gc_free (&gc); }else
@@ -454,7 +454,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -597,8 +597,8 @@ name_expand_size =64 +strlen (objbuf); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, - objbuf); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, + objbuf);string_mod (name_expand,CC_PRINT ,CC_CRLF ,'_' );string_mod ((char *)buf,CC_PRINT ,CC_CRLF ,'_' );setenv_str_incr (es, name_expand, (char *)buf);
src/openvpn/tls_crypt.c +2 -2
@@ -574,8 +574,8 @@ }char metadata_type_str[4 ] = {0 };/* Max value: 255 */ -openvpn_snprintf (metadata_type_str,sizeof (metadata_type_str), -"%i" , (uint8_t ) metadata_type); +snprintf (metadata_type_str,sizeof (metadata_type_str), +"%i" , (uint8_t ) metadata_type);struct env_set *es =env_set_create (NULL );setenv_str (es,"script_type" ,"tls-crypt-v2-verify" );setenv_str (es,"metadata_type" , metadata_type_str);
src/openvpn/tun.c +34 -34
164 lines not on this page · raw message
src/openvpn/win32.c +5 -20
@@ -885,8 +885,8 @@char force_path[256 ];char *sysroot =get_win_sys_path (); -if (!openvpn_snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , - sysroot, sysroot, sysroot)) +if (!snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , + sysroot, sysroot, sysroot)) {msg (M_WARN ,"env_block: default path truncated to %s" , force_path); }
@@ -1483,26 +1483,11 @@ }bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vswprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =L'\0' ; - } -return (len >=0 && len < size); -} - -bool get_openvpn_reg_value (const WCHAR *key,WCHAR *value,DWORD size) {WCHAR reg_path[256 ];HKEY hkey; -openvpn_swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME ); +swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME );LONG status =RegOpenKeyExW (HKEY_LOCAL_MACHINE , reg_path,0 ,KEY_READ , &hkey);if (status !=ERROR_SUCCESS )
@@ -1528,7 +1513,7 @@/* if we cannot find installation path from the registry, * use Windows directory as a fallback */ -openvpn_swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); +swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); }if ((install_path[wcslen (install_path) -1 ]) ==L'\\' )
@@ -1553,7 +1538,7 @@if (size ==0 ) {WCHAR val[MAX_PATH ] = {0 }; -openvpn_swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value); +swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value);_wputenv_s (ossl_env[i].name, val); } }
src/openvpn/win32.h +0 -8
@@ -319,14 +319,6 @@int openvpn_execve (const struct argv *a,const struct env_set *es,const unsigned int flags); -/* -* openvpn_swprintf() is currently only used by Windows code paths -* and when enabled for all platforms it will currently break older -* OpenBSD versions lacking vswprintf(3) support in their libc. -*/ -bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -/* Sleep that can be interrupted by signals and exit event */ void win32_sleep (const int n);
src/openvpn/xkey_helper.c +5 -5
@@ -205,7 +205,7 @@ }else { -openvpn_snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); } }else if (!strcmp (alg.keytype,"ED448" ) || !strcmp (alg.keytype,"ED25519" ))
@@ -229,8 +229,8 @@/* For undigested message, add hashalg=digest parameter */ else { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , -"RSA_PKCS1_PADDING" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , +"RSA_PKCS1_PADDING" , alg.mdname); } } else if (!strcmp(alg.padmode, "none") && (flags & MF_EXTERNAL_KEY_NOPADDING)
@@ -240,8 +240,8 @@ }else if (!strcmp (alg.padmode,"pss" ) && (flags &MF_EXTERNAL_KEY_PSSPAD )) { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , -"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , +"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); }else {
src/openvpnserv/common.c +11 -41
102 lines not on this page · raw message
src/openvpnserv/interactive.c +30 -27
162 lines not on this page · raw message
src/openvpnserv/service.h +0 -6
@@ -81,12 +81,6 @@ VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv); -BOOL openvpn_vsntprintf (LPTSTR str,size_t size,LPCTSTR format,va_list arglist); - -BOOL openvpn_sntprintf (LPTSTR str,size_t size,LPCTSTR format, ...); - -BOOL openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -DWORD GetOpenvpnSettings (settings_t *s);BOOL ReportStatusToSCMgr (SERVICE_STATUS_HANDLE service,SERVICE_STATUS *status);
src/openvpnserv/validate.c +1 -1
@@ -68,7 +68,7 @@/* convert fname to full path */ if (PathIsRelativeW (fname) ) { -openvpn_swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); +swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); config_file = tmp; }else
tests/unit_tests/openvpn/test_buffer.c +51 -0
63 lines not on this page · raw message
tests/unit_tests/openvpn/test_cryptoapi.c +5 -5
@@ -271,7 +271,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); ctx =find_certificate_in_store (select_string, user_store);if (ctx) {
@@ -304,7 +304,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); +snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the common name. But the returned cert may not exactly match
@@ -337,7 +337,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); +snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the issuer. But the returned cert may not exactly match
@@ -411,7 +411,7 @@ {continue ; } -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (Load_CryptoAPI_certificate (select_string, &x509, &privkey) !=1 ) {fail_msg ("Load_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
@@ -446,7 +446,7 @@SSL_CTX *ssl_ctx =SSL_CTX_new_ex (tls_libctx,NULL ,SSLv23_client_method ());assert_non_null (ssl_ctx); -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (!SSL_CTX_use_CryptoAPI_certificate (ssl_ctx, select_string)) {fail_msg ("SSL_CTX_use_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
tests/unit_tests/openvpn/test_pkcs11.c +3 -3
@@ -161,7 +161,7 @@ }else if (flags &GET_USER_PASS_PASSWORD_ONLY ) { -openvpn_snprintf (up->password,sizeof (up->password),"%s" ,PIN ); +snprintf (up->password,sizeof (up->password),"%s" ,PIN ); }else {
@@ -204,8 +204,8 @@ {fail_msg ("make tmpfile using template <%s> failed (error = %d)" , softhsm2_conf_path, errno); } -openvpn_snprintf (config,sizeof (config),"directories.tokendir=%s/" , - softhsm2_tokens_path); +snprintf (config,sizeof (config),"directories.tokendir=%s/" , + softhsm2_tokens_path);assert_int_equal (write (fd, config,strlen (config)),strlen (config));close (fd);
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac
Gerrit-Change-Number: 547
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: cron2, flichtenheld, ordex.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/547?usp=email )
Change subject: Remove openvpn_snprintf and similar functions
......................................................................
Patch Set 5:
(1 comment)
File tests/unit_tests/openvpn/test_buffer.c:
http://gerrit.openvpn.net/c/openvpn/+/547/comment/4a0f4211_d038f0d1 :
PS4, Line 401: #pragma GCC diagnostic pop
Quoted 1 line
yeah, although it seems work this way as well. Will fix.
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac
Gerrit-Change-Number: 547
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Fri, 03 May 2024 16:48:06 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: plaisthos <[email protected]...>
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: cron2, ordex, plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/547?usp=email )
Change subject: Remove openvpn_snprintf and similar functions
......................................................................
Patch Set 5:
(1 comment)
File src/openvpn/proxy.c:
http://gerrit.openvpn.net/c/openvpn/+/547/comment/1cc5661d_bc0d1f81 :
PS4, Line 966:
Quoted 1 line
What do you mean with spurious? It changes
openvpn_snprintfto snprintf
Sorry, seems I was too brief. I meant the empty line you inserted here. Either way, not important.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac
Gerrit-Change-Number: 547
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Mon, 06 May 2024 10:00:53 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: plaisthos <[email protected]...>
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: cron2, ordex, plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/547?usp=email )
Change subject: Remove openvpn_snprintf and similar functions
......................................................................
Patch Set 5: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac
Gerrit-Change-Number: 547
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Mon, 06 May 2024 10:18:07 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
PATCH v5 1/1 Remove openvpn_snprintf and similar functions
In reply to a message not in the archiveFrom: Arne Schwabe <[email protected]...>
Old Microsoft versions did strange behaviour but according to the newly added unit test and
https://stackoverflow.com/questions/7706936/is-snprintf-always-null-terminating
this is now standard conforming and we can use the normal snprintf method.
Microsoft own documentation to swprintf also says you nowadays need to define _CRT_NON_CONFORMING_SWPRINTFS to get to non-standard behaviour.
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/547
This mail reflects revision 5 of this Change.
Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]...>
src/openvpn/buffer.c +0 -26
@@ -279,32 +279,6 @@return ret; } - -/* -* This is necessary due to certain buggy implementations of snprintf, -* that don't guarantee null termination for size > 0. -* -* Return false on overflow. -* -* This functionality is duplicated in src/openvpnserv/common.c -* Any modifications here should be done to the other place as well. -*/ - -bool -openvpn_snprintf (char *str,size_t size,const char *format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vsnprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =0 ; - } -return (len >=0 && len < size); -} -/* * write a string to the end of a buffer that was * truncated by buf_printf
src/openvpn/buffer.h +0 -13
@@ -448,19 +448,6 @@*/ bool buf_puts (struct buffer *buf,const char *str); -/* -* Like snprintf but guarantees null termination for size > 0 -*/ -bool openvpn_snprintf(char *str, size_t size, const char *format, ...) -#ifdef __GNUC__ -#if __USE_MINGW_ANSI_STDIO -__attribute__ ((format(gnu_printf, 3, 4))) -#else -__attribute__ ((format(__printf__, 3, 4))) -#endif -#endif -; -/* * remove/add trailing characters
src/openvpn/crypto.c +2 -2
@@ -874,11 +874,11 @@key_direction_state_init (&kds, key_direction); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name);init_key_ctx (&ctx->encrypt, &key2->keys[kds.out_key], kt,OPENVPN_OP_ENCRYPT , log_prefix); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name);init_key_ctx (&ctx->decrypt, &key2->keys[kds.in_key], kt,OPENVPN_OP_DECRYPT , log_prefix);
src/openvpn/crypto_mbedtls.c +5 -5
@@ -128,7 +128,7 @@ {char prefix[256 ]; -if (!openvpn_snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) +if (!snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) {return mbed_log_err (flags, errval, func); }
@@ -239,11 +239,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) {return false; }
@@ -278,11 +278,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----" , name)) {return false; }
src/openvpn/dns.c +2 -2
@@ -349,11 +349,11 @@if (j <0 ) { - name_ok =openvpn_snprintf (name,sizeof (name), format, i); + name_ok =snprintf (name,sizeof (name), format, i); }else { - name_ok =openvpn_snprintf (name,sizeof (name), format, i, j); + name_ok =snprintf (name,sizeof (name), format, i, j); }if (!name_ok)
src/openvpn/env_set.c +4 -4
@@ -259,7 +259,7 @@ setenv_counter(struct env_set *es, const char *name, counter_type value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf), counter_format, value); +snprintf (buf,sizeof (buf), counter_format, value);setenv_str (es, name, buf); }
@@ -267,7 +267,7 @@ setenv_int(struct env_set *es, const char *name, int value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%d" , value); +snprintf (buf,sizeof (buf),"%d" , value);setenv_str (es, name, buf); }
@@ -275,7 +275,7 @@ setenv_long_long(struct env_set *es, const char *name, long long value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value); +snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value);setenv_str (es, name, buf); }
@@ -310,7 +310,7 @@strcpy (tmpname, name);while (NULL !=env_set_get (es, tmpname) && counter <1000 ) { -ASSERT (openvpn_snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); +ASSERT (snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); counter++; }if (counter <1000 )
src/openvpn/error.c +7 -7
@@ -274,14 +274,14 @@if ((flags &M_ERRNO ) && e) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , - m1,openvpn_strerror (e, crt_error, &gc), e); +snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , + m1,openvpn_strerror (e, crt_error, &gc), e);SWAP ; }if (flags &M_OPTERR ) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1); +snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1);SWAP ; }
@@ -321,10 +321,10 @@const struct virtual_output *vo =msg_get_virtual_output ();if (vo) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , - prefix, - prefix_sep, - m1); +snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , + prefix, + prefix_sep, + m1);virtual_output_print (vo, flags, m2); } }
src/openvpn/init.c +1 -1
@@ -359,7 +359,7 @@char *out =malloc (len);check_malloc_return (out); -openvpn_snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); +snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); *remote = out; }else
src/openvpn/manage.c +4 -4
@@ -515,8 +515,8 @@char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); -openvpn_snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes); +snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); +snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes);msg (M_CLIENT ,">BYTECOUNT:%s,%s" , in, out); }
@@ -528,8 +528,8 @@char in[32 ];char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, *bytes_in_total); -openvpn_snprintf (out,sizeof (out), counter_format, *bytes_out_total); +snprintf (in,sizeof (in), counter_format, *bytes_in_total); +snprintf (out,sizeof (out), counter_format, *bytes_out_total);msg (M_CLIENT ,">BYTECOUNT_CLI:%lu,%s,%s" , mdac->cid, in, out); mdac->bytecount_last_update = now; }
src/openvpn/options.c +4 -4
@@ -1427,7 +1427,7 @@for (int i =1 ; i <= opt_max; ++i) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , i); +snprintf (name,sizeof (name),"foreign_option_%d" , i);const char *env_str =env_set_get (es, name);const char *value =strchr (env_str,'=' ) +1 ;
@@ -1482,7 +1482,7 @@while (o->foreign_option_index < opt_max) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--); +snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--);setenv_del (es, name); } }
@@ -5674,8 +5674,8 @@#ifndef ENABLE_SMALL {char script_name[100 ]; -openvpn_snprintf (script_name,sizeof (script_name), -"--%s script" , type); +snprintf (script_name,sizeof (script_name), +"--%s script" , type);if (check_cmd_access (*script, script_name, (in_chroot ? options->chroot_dir :NULL ))) {
src/openvpn/pkcs11.c +3 -3
@@ -201,7 +201,7 @@CLEAR (token_resp); token_resp.defined = false; token_resp.nocache = true; - openvpn_snprintf( + snprintf( token_resp.username, sizeof(token_resp.username), "Please insert %s token",
@@ -245,7 +245,7 @@ASSERT (token!=NULL ); -openvpn_snprintf (prompt,sizeof (prompt),"%s token" , token->label); +snprintf (prompt,sizeof (prompt),"%s token" , token->label); token_pass.defined = false; token_pass.nocache = true;
@@ -719,7 +719,7 @@ id_resp.defined = false; id_resp.nocache = true; -openvpn_snprintf ( +snprintf ( id_resp.username,sizeof (id_resp.username), "Please specify PKCS#11 id to use"
src/openvpn/platform.c +3 -3
@@ -564,9 +564,9 @@ { ++attempts; -if (!openvpn_snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, - prefix, (unsigned long )get_random (), - (unsigned long )get_random ())) +if (!snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, + prefix, (unsigned long )get_random (), + (unsigned long )get_random ())) {msg (M_WARN ,"ERROR: temporary filename too long" );return NULL ;
src/openvpn/plugin.c +2 -2
@@ -260,7 +260,7 @@ {char full[PATH_MAX ]; -openvpn_snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); +snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); p->handle =dlopen (full,RTLD_NOW ); } else
@@ -409,7 +409,7 @@gc_init (&gc); msg_fmt =gc_malloc (ERR_BUF_SIZE , false, &gc); -openvpn_snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format); +snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format);x_msg_va (msg_flags, msg_fmt, arglist);gc_free (&gc);
src/openvpn/pool.c +1 -1
@@ -766,7 +766,7 @@ifconfig_pool_handle h;in_addr_t local, remote;char buf[256 ]; -openvpn_snprintf (buf,sizeof (buf),"common-name-%d" , i); +snprintf (buf,sizeof (buf),"common-name-%d" , i);#ifdef DUP_CN cn =NULL ;#else
src/openvpn/proxy.c +44 -43
185 lines not on this page · raw message
src/openvpn/ps.c +1 -1
@@ -354,7 +354,7 @@ fnlen =strlen (journal_dir) +strlen (t) +2 ; jfn = (char *)malloc (fnlen);check_malloc_return (jfn); -openvpn_snprintf (jfn, fnlen,"%s/%s" , journal_dir, t); +snprintf (jfn, fnlen,"%s/%s" , journal_dir, t);dmsg (D_PS_PROXY_DEBUG ,"PORT SHARE PROXY: client origin %s -> %s" , jfn, f); fd =platform_open (jfn,O_CREAT |O_TRUNC |O_WRONLY ,S_IRUSR |S_IWUSR |S_IRGRP );if (fd !=-1 )
src/openvpn/route.c +3 -3
@@ -1621,11 +1621,11 @@if (rgi) { -openvpn_snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); +snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); }else { -openvpn_snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); +snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); }bool ret =management_android_control (management,"ROUTE" , out); status = ret ?RTA_SUCCESS :RTA_ERROR ;
@@ -2000,7 +2000,7 @@#elif defined (TARGET_ANDROID )char out[64 ]; -openvpn_snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); +snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); status =management_android_control (management,"ROUTE6" , out);
src/openvpn/run_command.h +2 -2
@@ -66,8 +66,8 @@ {char msg[256 ]; -openvpn_snprintf (msg,sizeof (msg), -"WARNING: Failed running command (%s)" , hook); +snprintf (msg,sizeof (msg), +"WARNING: Failed running command (%s)" , hook);return openvpn_execve_check (a, es, flags |S_SCRIPT , msg); }
src/openvpn/socket.c +6 -6
@@ -2983,11 +2983,11 @@case AF_INET :if (flags &SA_IP_PORT ) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); }inet_ntop (AF_INET , &addr->addr.in4.sin_addr, buf,sizeof (buf));
@@ -2995,7 +2995,7 @@if ((flags &SA_IP_PORT ) && addr->addr.in4.sin_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in4.sin_port)); }break ;
@@ -3006,19 +3006,19 @@struct in_addr ia;memcpy (&ia.s_addr, &addr->addr.in6.sin6_addr.s6_addr[12 ],sizeof (ia.s_addr)); -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix);inet_ntop (AF_INET , &ia, buf,sizeof (buf)); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix);inet_ntop (AF_INET6 , &addr->addr.in6.sin6_addr, buf,sizeof (buf)); }setenv_str (es, name_buf, buf);if ((flags &SA_IP_PORT ) && addr->addr.in6.sin6_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in6.sin6_port)); }break ;
src/openvpn/socks.c +4 -3
@@ -109,9 +109,10 @@ "Authentication not possible."); goto cleanup; } -int sret =openvpn_snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , - (int )strlen (creds.username), creds.username, - (int )strlen (creds.password), creds.password); + +int sret =snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , + (int )strlen (creds.username), creds.username, + (int )strlen (creds.password), creds.password);ASSERT (sret <=sizeof (to_send)); size =send (sd, to_send,strlen (to_send),MSG_NOSIGNAL );
src/openvpn/ssl_mbedtls.c +6 -6
@@ -1531,16 +1531,16 @@char s2[256 ]; s1[0 ] = s2[0 ] =0 ; -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s" , - prefix, -mbedtls_ssl_get_version (ks_ssl->ctx), -mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s" , + prefix, +mbedtls_ssl_get_version (ks_ssl->ctx), +mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); cert =mbedtls_ssl_get_peer_cert (ks_ssl->ctx);if (cert !=NULL ) { -openvpn_snprintf (s2,sizeof (s2),", %u bit key" , - (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); +snprintf (s2,sizeof (s2),", %u bit key" , + (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); }msg (D_HANDSHAKE ,"%s%s" , s1, s2);
src/openvpn/ssl_ncp.c +2 -2
@@ -198,8 +198,8 @@size_t newlen =strlen (o->ncp_ciphers) +1 +strlen (ciphername) +1 ;char *ncp_ciphers =gc_malloc (newlen, false, &o->gc); -ASSERT (openvpn_snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, - ciphername)); +ASSERT (snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, + ciphername)); o->ncp_ciphers = ncp_ciphers; }
src/openvpn/ssl_openssl.c +16 -16
@@ -1774,7 +1774,7 @@if (!biofp) {char fn[256 ]; -openvpn_snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); +snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); biofp =fopen (fn,"w" );ASSERT (biofp); biofp_last_open =time (NULL );
@@ -2116,8 +2116,8 @@#endif /* if OPENSSL_VERSION_NUMBER < 0x30000000L */ } -openvpn_snprintf (buf, buflen,"%d bits %s%s" , -EVP_PKEY_bits (pkey), type, curve); +snprintf (buf, buflen,"%d bits %s%s" , +EVP_PKEY_bits (pkey), type, curve); }/**
@@ -2137,12 +2137,12 @@int signature_nid =X509_get_signature_nid (cert);if (signature_nid !=0 ) { -openvpn_snprintf (sig,sizeof (sig),", signature: %s" , -OBJ_nid2sn (signature_nid)); +snprintf (sig,sizeof (sig),", signature: %s" , +OBJ_nid2sn (signature_nid)); } -openvpn_snprintf (buf, buflen,", peer certificate: %s%s" , - pkeybuf, sig); +snprintf (buf, buflen,", peer certificate: %s%s" , + pkeybuf, sig);EVP_PKEY_free (pkey); }
@@ -2160,8 +2160,8 @@char pkeybuf[128 ] = {0 };print_pkey_details (pkey, pkeybuf,sizeof (pkeybuf)); -openvpn_snprintf (buf, buflen,", peer temporary key: %s" , - pkeybuf); +snprintf (buf, buflen,", peer temporary key: %s" , + pkeybuf);EVP_PKEY_free (pkey); }
@@ -2238,8 +2238,8 @@return ; } -openvpn_snprintf (buf, buflen,", peer signing digest/type: %s %s" , - peer_sig, peer_sig_type); +snprintf (buf, buflen,", peer signing digest/type: %s %s" , + peer_sig, peer_sig_type); }
@@ -2262,11 +2262,11 @@ s1[0 ] = s2[0 ] = s3[0 ] = s4[0 ] =0 ; ciph =SSL_get_current_cipher (ks_ssl->ssl); -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , - prefix, -SSL_get_version (ks_ssl->ssl), -SSL_CIPHER_get_version (ciph), -SSL_CIPHER_get_name (ciph)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , + prefix, +SSL_get_version (ks_ssl->ssl), +SSL_CIPHER_get_version (ciph), +SSL_CIPHER_get_name (ciph));X509 *cert =SSL_get_peer_certificate (ks_ssl->ssl);if (cert)
src/openvpn/ssl_verify.c +11 -11
@@ -421,12 +421,12 @@ }/* export subject name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth);setenv_str (es, envname, subject);#if 0 /* export common name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth);setenv_str (es, envname, common_name);#endif
@@ -435,24 +435,24 @@struct buffer sha1 =x509_get_sha1_fingerprint (peer_cert, &gc);struct buffer sha256 =x509_get_sha256_fingerprint (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha1),BLEN (&sha1),0 ,1 ,":" , &gc)); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , - cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , + cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha256),BLEN (&sha256),0 ,1 ,":" , &gc)); }/* export serial number as environmental variable */ serial =backend_x509_get_serial (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth);setenv_str (es, envname, serial);/* export serial number in hex as environmental variable */ serial =backend_x509_get_serial_hex (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth);setenv_str (es, envname, serial);gc_free (&gc);
@@ -569,7 +569,7 @@ goto cleanup; } -if (!openvpn_snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) +if (!snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) {msg (D_HANDSHAKE ,"VERIFY CRL: filename overflow" ); goto cleanup;
@@ -938,9 +938,9 @@if (!check_auth_pending_method (multi->peer_info, pending_method)) {char buf[128 ]; -openvpn_snprintf (buf,sizeof (buf), -"Authentication failed, required pending auth " -"method '%s' not supported" , pending_method); +snprintf (buf,sizeof (buf), +"Authentication failed, required pending auth " +"method '%s' not supported" , pending_method);auth_set_client_reason (multi, buf);msg (M_INFO ,"Client does not supported auth pending method " "'%s'" , pending_method);
src/openvpn/ssl_verify_mbedtls.c +7 -7
@@ -86,8 +86,8 @@char *serial =backend_x509_get_serial (cert, &gc); ret =mbedtls_x509_crt_verify_info (errstr,sizeof (errstr)-1 ,"" , *flags); -if (ret <=0 && !openvpn_snprintf (errstr,sizeof (errstr), -"Could not retrieve error string, flags=%" PRIx32, *flags)) +if (ret <=0 && !snprintf (errstr,sizeof (errstr), +"Could not retrieve error string, flags=%" PRIx32, *flags)) { errstr[0 ] ='\0' ; }
@@ -307,7 +307,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -431,13 +431,13 @@if (0 ==mbedtls_oid_get_attr_short_name (&name->oid, &shortname) ) { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , - cert_depth, shortname); +snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , + cert_depth, shortname); }else { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , - cert_depth); +snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , + cert_depth); }for (i =0 ; i < name->val.len; i++)
src/openvpn/ssl_verify_openssl.c +4 -4
@@ -279,7 +279,7 @@gc_free (&gc);return FAILURE ; } -openvpn_snprintf (common_name, cn_len,"0x%s" , serial); +snprintf (common_name, cn_len,"0x%s" , serial);gc_free (&gc); }else
@@ -454,7 +454,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -597,8 +597,8 @@ name_expand_size =64 +strlen (objbuf); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, - objbuf); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, + objbuf);string_mod (name_expand,CC_PRINT ,CC_CRLF ,'_' );string_mod ((char *)buf,CC_PRINT ,CC_CRLF ,'_' );setenv_str_incr (es, name_expand, (char *)buf);
src/openvpn/tls_crypt.c +2 -2
@@ -574,8 +574,8 @@ }char metadata_type_str[4 ] = {0 };/* Max value: 255 */ -openvpn_snprintf (metadata_type_str,sizeof (metadata_type_str), -"%i" , (uint8_t ) metadata_type); +snprintf (metadata_type_str,sizeof (metadata_type_str), +"%i" , (uint8_t ) metadata_type);struct env_set *es =env_set_create (NULL );setenv_str (es,"script_type" ,"tls-crypt-v2-verify" );setenv_str (es,"metadata_type" , metadata_type_str);
src/openvpn/tun.c +34 -34
164 lines not on this page · raw message
src/openvpn/win32.c +5 -20
@@ -885,8 +885,8 @@char force_path[256 ];char *sysroot =get_win_sys_path (); -if (!openvpn_snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , - sysroot, sysroot, sysroot)) +if (!snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , + sysroot, sysroot, sysroot)) {msg (M_WARN ,"env_block: default path truncated to %s" , force_path); }
@@ -1483,26 +1483,11 @@ }bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vswprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =L'\0' ; - } -return (len >=0 && len < size); -} - -bool get_openvpn_reg_value (const WCHAR *key,WCHAR *value,DWORD size) {WCHAR reg_path[256 ];HKEY hkey; -openvpn_swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME ); +swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME );LONG status =RegOpenKeyExW (HKEY_LOCAL_MACHINE , reg_path,0 ,KEY_READ , &hkey);if (status !=ERROR_SUCCESS )
@@ -1528,7 +1513,7 @@/* if we cannot find installation path from the registry, * use Windows directory as a fallback */ -openvpn_swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); +swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); }if ((install_path[wcslen (install_path) -1 ]) ==L'\\' )
@@ -1553,7 +1538,7 @@if (size ==0 ) {WCHAR val[MAX_PATH ] = {0 }; -openvpn_swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value); +swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value);_wputenv_s (ossl_env[i].name, val); } }
src/openvpn/win32.h +0 -8
@@ -319,14 +319,6 @@int openvpn_execve (const struct argv *a,const struct env_set *es,const unsigned int flags); -/* -* openvpn_swprintf() is currently only used by Windows code paths -* and when enabled for all platforms it will currently break older -* OpenBSD versions lacking vswprintf(3) support in their libc. -*/ -bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -/* Sleep that can be interrupted by signals and exit event */ void win32_sleep (const int n);
src/openvpn/xkey_helper.c +5 -5
@@ -205,7 +205,7 @@ }else { -openvpn_snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); } }else if (!strcmp (alg.keytype,"ED448" ) || !strcmp (alg.keytype,"ED25519" ))
@@ -229,8 +229,8 @@/* For undigested message, add hashalg=digest parameter */ else { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , -"RSA_PKCS1_PADDING" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , +"RSA_PKCS1_PADDING" , alg.mdname); } } else if (!strcmp(alg.padmode, "none") && (flags & MF_EXTERNAL_KEY_NOPADDING)
@@ -240,8 +240,8 @@ }else if (!strcmp (alg.padmode,"pss" ) && (flags &MF_EXTERNAL_KEY_PSSPAD )) { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , -"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , +"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); }else {
src/openvpnserv/common.c +11 -41
102 lines not on this page · raw message
src/openvpnserv/interactive.c +30 -27
162 lines not on this page · raw message
src/openvpnserv/service.h +0 -6
@@ -81,12 +81,6 @@ VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv); -BOOL openvpn_vsntprintf (LPTSTR str,size_t size,LPCTSTR format,va_list arglist); - -BOOL openvpn_sntprintf (LPTSTR str,size_t size,LPCTSTR format, ...); - -BOOL openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -DWORD GetOpenvpnSettings (settings_t *s);BOOL ReportStatusToSCMgr (SERVICE_STATUS_HANDLE service,SERVICE_STATUS *status);
src/openvpnserv/validate.c +1 -1
@@ -68,7 +68,7 @@/* convert fname to full path */ if (PathIsRelativeW (fname) ) { -openvpn_swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); +swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); config_file = tmp; }else
tests/unit_tests/openvpn/test_buffer.c +51 -0
63 lines not on this page · raw message
tests/unit_tests/openvpn/test_cryptoapi.c +5 -5
@@ -271,7 +271,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); ctx =find_certificate_in_store (select_string, user_store);if (ctx) {
@@ -304,7 +304,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); +snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the common name. But the returned cert may not exactly match
@@ -337,7 +337,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); +snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the issuer. But the returned cert may not exactly match
@@ -411,7 +411,7 @@ {continue ; } -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (Load_CryptoAPI_certificate (select_string, &x509, &privkey) !=1 ) {fail_msg ("Load_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
@@ -446,7 +446,7 @@SSL_CTX *ssl_ctx =SSL_CTX_new_ex (tls_libctx,NULL ,SSLv23_client_method ());assert_non_null (ssl_ctx); -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (!SSL_CTX_use_CryptoAPI_certificate (ssl_ctx, select_string)) {fail_msg ("SSL_CTX_use_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
tests/unit_tests/openvpn/test_pkcs11.c +3 -3
@@ -161,7 +161,7 @@ }else if (flags &GET_USER_PASS_PASSWORD_ONLY ) { -openvpn_snprintf (up->password,sizeof (up->password),"%s" ,PIN ); +snprintf (up->password,sizeof (up->password),"%s" ,PIN ); }else {
@@ -204,8 +204,8 @@ {fail_msg ("make tmpfile using template <%s> failed (error = %d)" , softhsm2_conf_path, errno); } -openvpn_snprintf (config,sizeof (config),"directories.tokendir=%s/" , - softhsm2_tokens_path); +snprintf (config,sizeof (config),"directories.tokendir=%s/" , + softhsm2_tokens_path);assert_int_equal (write (fd, config,strlen (config)),strlen (config));close (fd);
[Openvpn-devel] [PATCH applied] Re: Remove openvpn_snprintf and similar functions
Stared a bit at the difference of v2 and v5 (windows pipe cast plus clang pragma). All the rest is identical to v2, and trivial in itself ("git show -w -I snprintf").
Self test passes, and compilation / GHA also passes.
I have adapted the "We know that the results truncated" comment (added "will be") - I think that was in v2 already, or in Antonio's comment on v2, but it's a comment, so no good in asking for a v6.
Your patch has been applied to the master branch.
commit 130548fe4d23afac5d2948d4e5ee164eef635cfd
Author: Arne Schwabe Date: Mon May 6 12:27:10 2024 +0200
Remove openvpn_snprintf and similar functions
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Frank Lichtenheld <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg28617.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
cron2 has uploaded a new patch set (#6) to the change originally created by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/547?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld
Change subject: Remove openvpn_snprintf and similar functions
......................................................................
Remove openvpn_snprintf and similar functions
Old Microsoft versions did strange behaviour but according to the newly added unit test and
https://stackoverflow.com/questions/7706936/is-snprintf-always-null-terminating
this is now standard conforming and we can use the normal snprintf method.
Microsoft own documentation to swprintf also says you nowadays need to define _CRT_NON_CONFORMING_SWPRINTFS to get to non-standard behaviour.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg28617.html
---
M src/openvpn/buffer.c
M src/openvpn/buffer.h
M src/openvpn/crypto.c
M src/openvpn/crypto_mbedtls.c
M src/openvpn/dns.c
M src/openvpn/env_set.c
M src/openvpn/error.c
M src/openvpn/init.c
M src/openvpn/manage.c
M src/openvpn/options.c
M src/openvpn/pkcs11.c
M src/openvpn/platform.c
M src/openvpn/plugin.c
M src/openvpn/pool.c
M src/openvpn/proxy.c
M src/openvpn/ps.c
M src/openvpn/route.c
M src/openvpn/run_command.h
M src/openvpn/socket.c
M src/openvpn/socks.c
M src/openvpn/ssl_mbedtls.c
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_openssl.c
M src/openvpn/ssl_verify.c
M src/openvpn/ssl_verify_mbedtls.c
M src/openvpn/ssl_verify_openssl.c
M src/openvpn/tls_crypt.c
M src/openvpn/tun.c
M src/openvpn/win32.c
M src/openvpn/win32.h
M src/openvpn/xkey_helper.c
M src/openvpnserv/common.c
M src/openvpnserv/interactive.c
M src/openvpnserv/service.h
M src/openvpnserv/validate.c
M tests/unit_tests/openvpn/test_buffer.c
M tests/unit_tests/openvpn/test_cryptoapi.c
M tests/unit_tests/openvpn/test_pkcs11.c
38 files changed, 291 insertions(+), 333 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/47/547/6
src/openvpn/buffer.c +0 -26
@@ -279,32 +279,6 @@return ret; } - -/* -* This is necessary due to certain buggy implementations of snprintf, -* that don't guarantee null termination for size > 0. -* -* Return false on overflow. -* -* This functionality is duplicated in src/openvpnserv/common.c -* Any modifications here should be done to the other place as well. -*/ - -bool -openvpn_snprintf (char *str,size_t size,const char *format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vsnprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =0 ; - } -return (len >=0 && len < size); -} -/* * write a string to the end of a buffer that was * truncated by buf_printf
src/openvpn/buffer.h +0 -13
@@ -448,19 +448,6 @@*/ bool buf_puts (struct buffer *buf,const char *str); -/* -* Like snprintf but guarantees null termination for size > 0 -*/ -bool openvpn_snprintf(char *str, size_t size, const char *format, ...) -#ifdef __GNUC__ -#if __USE_MINGW_ANSI_STDIO -__attribute__ ((format(gnu_printf, 3, 4))) -#else -__attribute__ ((format(__printf__, 3, 4))) -#endif -#endif -; -/* * remove/add trailing characters
src/openvpn/crypto.c +2 -2
@@ -874,11 +874,11 @@key_direction_state_init (&kds, key_direction); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name);init_key_ctx (&ctx->encrypt, &key2->keys[kds.out_key], kt,OPENVPN_OP_ENCRYPT , log_prefix); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name);init_key_ctx (&ctx->decrypt, &key2->keys[kds.in_key], kt,OPENVPN_OP_DECRYPT , log_prefix);
src/openvpn/crypto_mbedtls.c +5 -5
@@ -128,7 +128,7 @@ {char prefix[256 ]; -if (!openvpn_snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) +if (!snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) {return mbed_log_err (flags, errval, func); }
@@ -239,11 +239,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) {return false; }
@@ -278,11 +278,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----" , name)) {return false; }
src/openvpn/dns.c +2 -2
@@ -349,11 +349,11 @@if (j <0 ) { - name_ok =openvpn_snprintf (name,sizeof (name), format, i); + name_ok =snprintf (name,sizeof (name), format, i); }else { - name_ok =openvpn_snprintf (name,sizeof (name), format, i, j); + name_ok =snprintf (name,sizeof (name), format, i, j); }if (!name_ok)
src/openvpn/env_set.c +4 -4
@@ -259,7 +259,7 @@ setenv_counter(struct env_set *es, const char *name, counter_type value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf), counter_format, value); +snprintf (buf,sizeof (buf), counter_format, value);setenv_str (es, name, buf); }
@@ -267,7 +267,7 @@ setenv_int(struct env_set *es, const char *name, int value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%d" , value); +snprintf (buf,sizeof (buf),"%d" , value);setenv_str (es, name, buf); }
@@ -275,7 +275,7 @@ setenv_long_long(struct env_set *es, const char *name, long long value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value); +snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value);setenv_str (es, name, buf); }
@@ -310,7 +310,7 @@strcpy (tmpname, name);while (NULL !=env_set_get (es, tmpname) && counter <1000 ) { -ASSERT (openvpn_snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); +ASSERT (snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); counter++; }if (counter <1000 )
src/openvpn/error.c +7 -7
@@ -274,14 +274,14 @@if ((flags &M_ERRNO ) && e) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , - m1,openvpn_strerror (e, crt_error, &gc), e); +snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , + m1,openvpn_strerror (e, crt_error, &gc), e);SWAP ; }if (flags &M_OPTERR ) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1); +snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1);SWAP ; }
@@ -321,10 +321,10 @@const struct virtual_output *vo =msg_get_virtual_output ();if (vo) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , - prefix, - prefix_sep, - m1); +snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , + prefix, + prefix_sep, + m1);virtual_output_print (vo, flags, m2); } }
src/openvpn/init.c +1 -1
@@ -359,7 +359,7 @@char *out =malloc (len);check_malloc_return (out); -openvpn_snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); +snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); *remote = out; }else
src/openvpn/manage.c +4 -4
@@ -515,8 +515,8 @@char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); -openvpn_snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes); +snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); +snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes);msg (M_CLIENT ,">BYTECOUNT:%s,%s" , in, out); }
@@ -528,8 +528,8 @@char in[32 ];char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, *bytes_in_total); -openvpn_snprintf (out,sizeof (out), counter_format, *bytes_out_total); +snprintf (in,sizeof (in), counter_format, *bytes_in_total); +snprintf (out,sizeof (out), counter_format, *bytes_out_total);msg (M_CLIENT ,">BYTECOUNT_CLI:%lu,%s,%s" , mdac->cid, in, out); mdac->bytecount_last_update = now; }
src/openvpn/options.c +4 -4
@@ -1427,7 +1427,7 @@for (int i =1 ; i <= opt_max; ++i) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , i); +snprintf (name,sizeof (name),"foreign_option_%d" , i);const char *env_str =env_set_get (es, name);const char *value =strchr (env_str,'=' ) +1 ;
@@ -1482,7 +1482,7 @@while (o->foreign_option_index < opt_max) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--); +snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--);setenv_del (es, name); } }
@@ -5674,8 +5674,8 @@#ifndef ENABLE_SMALL {char script_name[100 ]; -openvpn_snprintf (script_name,sizeof (script_name), -"--%s script" , type); +snprintf (script_name,sizeof (script_name), +"--%s script" , type);if (check_cmd_access (*script, script_name, (in_chroot ? options->chroot_dir :NULL ))) {
src/openvpn/pkcs11.c +3 -3
@@ -201,7 +201,7 @@CLEAR (token_resp); token_resp.defined = false; token_resp.nocache = true; - openvpn_snprintf( + snprintf( token_resp.username, sizeof(token_resp.username), "Please insert %s token",
@@ -245,7 +245,7 @@ASSERT (token!=NULL ); -openvpn_snprintf (prompt,sizeof (prompt),"%s token" , token->label); +snprintf (prompt,sizeof (prompt),"%s token" , token->label); token_pass.defined = false; token_pass.nocache = true;
@@ -719,7 +719,7 @@ id_resp.defined = false; id_resp.nocache = true; -openvpn_snprintf ( +snprintf ( id_resp.username,sizeof (id_resp.username), "Please specify PKCS#11 id to use"
src/openvpn/platform.c +3 -3
@@ -564,9 +564,9 @@ { ++attempts; -if (!openvpn_snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, - prefix, (unsigned long )get_random (), - (unsigned long )get_random ())) +if (!snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, + prefix, (unsigned long )get_random (), + (unsigned long )get_random ())) {msg (M_WARN ,"ERROR: temporary filename too long" );return NULL ;
src/openvpn/plugin.c +2 -2
@@ -260,7 +260,7 @@ {char full[PATH_MAX ]; -openvpn_snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); +snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); p->handle =dlopen (full,RTLD_NOW ); } else
@@ -409,7 +409,7 @@gc_init (&gc); msg_fmt =gc_malloc (ERR_BUF_SIZE , false, &gc); -openvpn_snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format); +snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format);x_msg_va (msg_flags, msg_fmt, arglist);gc_free (&gc);
src/openvpn/pool.c +1 -1
@@ -766,7 +766,7 @@ifconfig_pool_handle h;in_addr_t local, remote;char buf[256 ]; -openvpn_snprintf (buf,sizeof (buf),"common-name-%d" , i); +snprintf (buf,sizeof (buf),"common-name-%d" , i);#ifdef DUP_CN cn =NULL ;#else
src/openvpn/proxy.c +44 -43
185 lines not on this page · raw message
src/openvpn/ps.c +1 -1
@@ -354,7 +354,7 @@ fnlen =strlen (journal_dir) +strlen (t) +2 ; jfn = (char *)malloc (fnlen);check_malloc_return (jfn); -openvpn_snprintf (jfn, fnlen,"%s/%s" , journal_dir, t); +snprintf (jfn, fnlen,"%s/%s" , journal_dir, t);dmsg (D_PS_PROXY_DEBUG ,"PORT SHARE PROXY: client origin %s -> %s" , jfn, f); fd =platform_open (jfn,O_CREAT |O_TRUNC |O_WRONLY ,S_IRUSR |S_IWUSR |S_IRGRP );if (fd !=-1 )
src/openvpn/route.c +3 -3
@@ -1621,11 +1621,11 @@if (rgi) { -openvpn_snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); +snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); }else { -openvpn_snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); +snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); }bool ret =management_android_control (management,"ROUTE" , out); status = ret ?RTA_SUCCESS :RTA_ERROR ;
@@ -2000,7 +2000,7 @@#elif defined (TARGET_ANDROID )char out[64 ]; -openvpn_snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); +snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); status =management_android_control (management,"ROUTE6" , out);
src/openvpn/run_command.h +2 -2
@@ -66,8 +66,8 @@ {char msg[256 ]; -openvpn_snprintf (msg,sizeof (msg), -"WARNING: Failed running command (%s)" , hook); +snprintf (msg,sizeof (msg), +"WARNING: Failed running command (%s)" , hook);return openvpn_execve_check (a, es, flags |S_SCRIPT , msg); }
src/openvpn/socket.c +6 -6
@@ -2983,11 +2983,11 @@case AF_INET :if (flags &SA_IP_PORT ) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); }inet_ntop (AF_INET , &addr->addr.in4.sin_addr, buf,sizeof (buf));
@@ -2995,7 +2995,7 @@if ((flags &SA_IP_PORT ) && addr->addr.in4.sin_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in4.sin_port)); }break ;
@@ -3006,19 +3006,19 @@struct in_addr ia;memcpy (&ia.s_addr, &addr->addr.in6.sin6_addr.s6_addr[12 ],sizeof (ia.s_addr)); -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix);inet_ntop (AF_INET , &ia, buf,sizeof (buf)); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix);inet_ntop (AF_INET6 , &addr->addr.in6.sin6_addr, buf,sizeof (buf)); }setenv_str (es, name_buf, buf);if ((flags &SA_IP_PORT ) && addr->addr.in6.sin6_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in6.sin6_port)); }break ;
src/openvpn/socks.c +4 -3
@@ -109,9 +109,10 @@ "Authentication not possible."); goto cleanup; } -int sret =openvpn_snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , - (int )strlen (creds.username), creds.username, - (int )strlen (creds.password), creds.password); + +int sret =snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , + (int )strlen (creds.username), creds.username, + (int )strlen (creds.password), creds.password);ASSERT (sret <=sizeof (to_send)); size =send (sd, to_send,strlen (to_send),MSG_NOSIGNAL );
src/openvpn/ssl_mbedtls.c +6 -6
@@ -1531,16 +1531,16 @@char s2[256 ]; s1[0 ] = s2[0 ] =0 ; -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s" , - prefix, -mbedtls_ssl_get_version (ks_ssl->ctx), -mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s" , + prefix, +mbedtls_ssl_get_version (ks_ssl->ctx), +mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); cert =mbedtls_ssl_get_peer_cert (ks_ssl->ctx);if (cert !=NULL ) { -openvpn_snprintf (s2,sizeof (s2),", %u bit key" , - (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); +snprintf (s2,sizeof (s2),", %u bit key" , + (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); }msg (D_HANDSHAKE ,"%s%s" , s1, s2);
src/openvpn/ssl_ncp.c +2 -2
@@ -198,8 +198,8 @@size_t newlen =strlen (o->ncp_ciphers) +1 +strlen (ciphername) +1 ;char *ncp_ciphers =gc_malloc (newlen, false, &o->gc); -ASSERT (openvpn_snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, - ciphername)); +ASSERT (snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, + ciphername)); o->ncp_ciphers = ncp_ciphers; }
src/openvpn/ssl_openssl.c +16 -16
@@ -1774,7 +1774,7 @@if (!biofp) {char fn[256 ]; -openvpn_snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); +snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); biofp =fopen (fn,"w" );ASSERT (biofp); biofp_last_open =time (NULL );
@@ -2116,8 +2116,8 @@#endif /* if OPENSSL_VERSION_NUMBER < 0x30000000L */ } -openvpn_snprintf (buf, buflen,"%d bits %s%s" , -EVP_PKEY_bits (pkey), type, curve); +snprintf (buf, buflen,"%d bits %s%s" , +EVP_PKEY_bits (pkey), type, curve); }/**
@@ -2137,12 +2137,12 @@int signature_nid =X509_get_signature_nid (cert);if (signature_nid !=0 ) { -openvpn_snprintf (sig,sizeof (sig),", signature: %s" , -OBJ_nid2sn (signature_nid)); +snprintf (sig,sizeof (sig),", signature: %s" , +OBJ_nid2sn (signature_nid)); } -openvpn_snprintf (buf, buflen,", peer certificate: %s%s" , - pkeybuf, sig); +snprintf (buf, buflen,", peer certificate: %s%s" , + pkeybuf, sig);EVP_PKEY_free (pkey); }
@@ -2160,8 +2160,8 @@char pkeybuf[128 ] = {0 };print_pkey_details (pkey, pkeybuf,sizeof (pkeybuf)); -openvpn_snprintf (buf, buflen,", peer temporary key: %s" , - pkeybuf); +snprintf (buf, buflen,", peer temporary key: %s" , + pkeybuf);EVP_PKEY_free (pkey); }
@@ -2238,8 +2238,8 @@return ; } -openvpn_snprintf (buf, buflen,", peer signing digest/type: %s %s" , - peer_sig, peer_sig_type); +snprintf (buf, buflen,", peer signing digest/type: %s %s" , + peer_sig, peer_sig_type); }
@@ -2262,11 +2262,11 @@ s1[0 ] = s2[0 ] = s3[0 ] = s4[0 ] =0 ; ciph =SSL_get_current_cipher (ks_ssl->ssl); -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , - prefix, -SSL_get_version (ks_ssl->ssl), -SSL_CIPHER_get_version (ciph), -SSL_CIPHER_get_name (ciph)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , + prefix, +SSL_get_version (ks_ssl->ssl), +SSL_CIPHER_get_version (ciph), +SSL_CIPHER_get_name (ciph));X509 *cert =SSL_get_peer_certificate (ks_ssl->ssl);if (cert)
src/openvpn/ssl_verify.c +11 -11
@@ -421,12 +421,12 @@ }/* export subject name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth);setenv_str (es, envname, subject);#if 0 /* export common name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth);setenv_str (es, envname, common_name);#endif
@@ -435,24 +435,24 @@struct buffer sha1 =x509_get_sha1_fingerprint (peer_cert, &gc);struct buffer sha256 =x509_get_sha256_fingerprint (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha1),BLEN (&sha1),0 ,1 ,":" , &gc)); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , - cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , + cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha256),BLEN (&sha256),0 ,1 ,":" , &gc)); }/* export serial number as environmental variable */ serial =backend_x509_get_serial (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth);setenv_str (es, envname, serial);/* export serial number in hex as environmental variable */ serial =backend_x509_get_serial_hex (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth);setenv_str (es, envname, serial);gc_free (&gc);
@@ -569,7 +569,7 @@ goto cleanup; } -if (!openvpn_snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) +if (!snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) {msg (D_HANDSHAKE ,"VERIFY CRL: filename overflow" ); goto cleanup;
@@ -938,9 +938,9 @@if (!check_auth_pending_method (multi->peer_info, pending_method)) {char buf[128 ]; -openvpn_snprintf (buf,sizeof (buf), -"Authentication failed, required pending auth " -"method '%s' not supported" , pending_method); +snprintf (buf,sizeof (buf), +"Authentication failed, required pending auth " +"method '%s' not supported" , pending_method);auth_set_client_reason (multi, buf);msg (M_INFO ,"Client does not supported auth pending method " "'%s'" , pending_method);
src/openvpn/ssl_verify_mbedtls.c +7 -7
@@ -86,8 +86,8 @@char *serial =backend_x509_get_serial (cert, &gc); ret =mbedtls_x509_crt_verify_info (errstr,sizeof (errstr)-1 ,"" , *flags); -if (ret <=0 && !openvpn_snprintf (errstr,sizeof (errstr), -"Could not retrieve error string, flags=%" PRIx32, *flags)) +if (ret <=0 && !snprintf (errstr,sizeof (errstr), +"Could not retrieve error string, flags=%" PRIx32, *flags)) { errstr[0 ] ='\0' ; }
@@ -307,7 +307,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -431,13 +431,13 @@if (0 ==mbedtls_oid_get_attr_short_name (&name->oid, &shortname) ) { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , - cert_depth, shortname); +snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , + cert_depth, shortname); }else { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , - cert_depth); +snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , + cert_depth); }for (i =0 ; i < name->val.len; i++)
src/openvpn/ssl_verify_openssl.c +4 -4
@@ -279,7 +279,7 @@gc_free (&gc);return FAILURE ; } -openvpn_snprintf (common_name, cn_len,"0x%s" , serial); +snprintf (common_name, cn_len,"0x%s" , serial);gc_free (&gc); }else
@@ -454,7 +454,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -597,8 +597,8 @@ name_expand_size =64 +strlen (objbuf); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, - objbuf); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, + objbuf);string_mod (name_expand,CC_PRINT ,CC_CRLF ,'_' );string_mod ((char *)buf,CC_PRINT ,CC_CRLF ,'_' );setenv_str_incr (es, name_expand, (char *)buf);
src/openvpn/tls_crypt.c +2 -2
@@ -574,8 +574,8 @@ }char metadata_type_str[4 ] = {0 };/* Max value: 255 */ -openvpn_snprintf (metadata_type_str,sizeof (metadata_type_str), -"%i" , (uint8_t ) metadata_type); +snprintf (metadata_type_str,sizeof (metadata_type_str), +"%i" , (uint8_t ) metadata_type);struct env_set *es =env_set_create (NULL );setenv_str (es,"script_type" ,"tls-crypt-v2-verify" );setenv_str (es,"metadata_type" , metadata_type_str);
src/openvpn/tun.c +34 -34
164 lines not on this page · raw message
src/openvpn/win32.c +5 -20
@@ -885,8 +885,8 @@char force_path[256 ];char *sysroot =get_win_sys_path (); -if (!openvpn_snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , - sysroot, sysroot, sysroot)) +if (!snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , + sysroot, sysroot, sysroot)) {msg (M_WARN ,"env_block: default path truncated to %s" , force_path); }
@@ -1483,26 +1483,11 @@ }bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vswprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =L'\0' ; - } -return (len >=0 && len < size); -} - -bool get_openvpn_reg_value (const WCHAR *key,WCHAR *value,DWORD size) {WCHAR reg_path[256 ];HKEY hkey; -openvpn_swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME ); +swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME );LONG status =RegOpenKeyExW (HKEY_LOCAL_MACHINE , reg_path,0 ,KEY_READ , &hkey);if (status !=ERROR_SUCCESS )
@@ -1528,7 +1513,7 @@/* if we cannot find installation path from the registry, * use Windows directory as a fallback */ -openvpn_swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); +swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); }if ((install_path[wcslen (install_path) -1 ]) ==L'\\' )
@@ -1553,7 +1538,7 @@if (size ==0 ) {WCHAR val[MAX_PATH ] = {0 }; -openvpn_swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value); +swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value);_wputenv_s (ossl_env[i].name, val); } }
src/openvpn/win32.h +0 -8
@@ -319,14 +319,6 @@int openvpn_execve (const struct argv *a,const struct env_set *es,const unsigned int flags); -/* -* openvpn_swprintf() is currently only used by Windows code paths -* and when enabled for all platforms it will currently break older -* OpenBSD versions lacking vswprintf(3) support in their libc. -*/ -bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -/* Sleep that can be interrupted by signals and exit event */ void win32_sleep (const int n);
src/openvpn/xkey_helper.c +5 -5
@@ -205,7 +205,7 @@ }else { -openvpn_snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); } }else if (!strcmp (alg.keytype,"ED448" ) || !strcmp (alg.keytype,"ED25519" ))
@@ -229,8 +229,8 @@/* For undigested message, add hashalg=digest parameter */ else { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , -"RSA_PKCS1_PADDING" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , +"RSA_PKCS1_PADDING" , alg.mdname); } } else if (!strcmp(alg.padmode, "none") && (flags & MF_EXTERNAL_KEY_NOPADDING)
@@ -240,8 +240,8 @@ }else if (!strcmp (alg.padmode,"pss" ) && (flags &MF_EXTERNAL_KEY_PSSPAD )) { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , -"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , +"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); }else {
src/openvpnserv/common.c +11 -41
102 lines not on this page · raw message
src/openvpnserv/interactive.c +30 -27
162 lines not on this page · raw message
src/openvpnserv/service.h +0 -6
@@ -81,12 +81,6 @@ VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv); -BOOL openvpn_vsntprintf (LPTSTR str,size_t size,LPCTSTR format,va_list arglist); - -BOOL openvpn_sntprintf (LPTSTR str,size_t size,LPCTSTR format, ...); - -BOOL openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -DWORD GetOpenvpnSettings (settings_t *s);BOOL ReportStatusToSCMgr (SERVICE_STATUS_HANDLE service,SERVICE_STATUS *status);
src/openvpnserv/validate.c +1 -1
@@ -68,7 +68,7 @@/* convert fname to full path */ if (PathIsRelativeW (fname) ) { -openvpn_swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); +swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); config_file = tmp; }else
tests/unit_tests/openvpn/test_buffer.c +51 -0
63 lines not on this page · raw message
tests/unit_tests/openvpn/test_cryptoapi.c +5 -5
@@ -271,7 +271,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); ctx =find_certificate_in_store (select_string, user_store);if (ctx) {
@@ -304,7 +304,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); +snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the common name. But the returned cert may not exactly match
@@ -337,7 +337,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); +snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the issuer. But the returned cert may not exactly match
@@ -411,7 +411,7 @@ {continue ; } -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (Load_CryptoAPI_certificate (select_string, &x509, &privkey) !=1 ) {fail_msg ("Load_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
@@ -446,7 +446,7 @@SSL_CTX *ssl_ctx =SSL_CTX_new_ex (tls_libctx,NULL ,SSLv23_client_method ());assert_non_null (ssl_ctx); -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (!SSL_CTX_use_CryptoAPI_certificate (ssl_ctx, select_string)) {fail_msg ("SSL_CTX_use_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
tests/unit_tests/openvpn/test_pkcs11.c +3 -3
@@ -161,7 +161,7 @@ }else if (flags &GET_USER_PASS_PASSWORD_ONLY ) { -openvpn_snprintf (up->password,sizeof (up->password),"%s" ,PIN ); +snprintf (up->password,sizeof (up->password),"%s" ,PIN ); }else {
@@ -204,8 +204,8 @@ {fail_msg ("make tmpfile using template <%s> failed (error = %d)" , softhsm2_conf_path, errno); } -openvpn_snprintf (config,sizeof (config),"directories.tokendir=%s/" , - softhsm2_tokens_path); +snprintf (config,sizeof (config),"directories.tokendir=%s/" , + softhsm2_tokens_path);assert_int_equal (write (fd, config,strlen (config)),strlen (config));close (fd);
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac
Gerrit-Change-Number: 547
Gerrit-PatchSet: 6
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/547?usp=email )
Change subject: Remove openvpn_snprintf and similar functions
......................................................................
Remove openvpn_snprintf and similar functions
Old Microsoft versions did strange behaviour but according to the newly added unit test and
https://stackoverflow.com/questions/7706936/is-snprintf-always-null-terminating
this is now standard conforming and we can use the normal snprintf method.
Microsoft own documentation to swprintf also says you nowadays need to define _CRT_NON_CONFORMING_SWPRINTFS to get to non-standard behaviour.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg28617.html
---
M src/openvpn/buffer.c
M src/openvpn/buffer.h
M src/openvpn/crypto.c
M src/openvpn/crypto_mbedtls.c
M src/openvpn/dns.c
M src/openvpn/env_set.c
M src/openvpn/error.c
M src/openvpn/init.c
M src/openvpn/manage.c
M src/openvpn/options.c
M src/openvpn/pkcs11.c
M src/openvpn/platform.c
M src/openvpn/plugin.c
M src/openvpn/pool.c
M src/openvpn/proxy.c
M src/openvpn/ps.c
M src/openvpn/route.c
M src/openvpn/run_command.h
M src/openvpn/socket.c
M src/openvpn/socks.c
M src/openvpn/ssl_mbedtls.c
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_openssl.c
M src/openvpn/ssl_verify.c
M src/openvpn/ssl_verify_mbedtls.c
M src/openvpn/ssl_verify_openssl.c
M src/openvpn/tls_crypt.c
M src/openvpn/tun.c
M src/openvpn/win32.c
M src/openvpn/win32.h
M src/openvpn/xkey_helper.c
M src/openvpnserv/common.c
M src/openvpnserv/interactive.c
M src/openvpnserv/service.h
M src/openvpnserv/validate.c
M tests/unit_tests/openvpn/test_buffer.c
M tests/unit_tests/openvpn/test_cryptoapi.c
M tests/unit_tests/openvpn/test_pkcs11.c
38 files changed, 291 insertions(+), 333 deletions(-)
src/openvpn/buffer.c +0 -26
@@ -279,32 +279,6 @@return ret; } - -/* -* This is necessary due to certain buggy implementations of snprintf, -* that don't guarantee null termination for size > 0. -* -* Return false on overflow. -* -* This functionality is duplicated in src/openvpnserv/common.c -* Any modifications here should be done to the other place as well. -*/ - -bool -openvpn_snprintf (char *str,size_t size,const char *format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vsnprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =0 ; - } -return (len >=0 && len < size); -} -/* * write a string to the end of a buffer that was * truncated by buf_printf
src/openvpn/buffer.h +0 -13
@@ -448,19 +448,6 @@*/ bool buf_puts (struct buffer *buf,const char *str); -/* -* Like snprintf but guarantees null termination for size > 0 -*/ -bool openvpn_snprintf(char *str, size_t size, const char *format, ...) -#ifdef __GNUC__ -#if __USE_MINGW_ANSI_STDIO -__attribute__ ((format(gnu_printf, 3, 4))) -#else -__attribute__ ((format(__printf__, 3, 4))) -#endif -#endif -; -/* * remove/add trailing characters
src/openvpn/crypto.c +2 -2
@@ -874,11 +874,11 @@key_direction_state_init (&kds, key_direction); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Outgoing %s" , name);init_key_ctx (&ctx->encrypt, &key2->keys[kds.out_key], kt,OPENVPN_OP_ENCRYPT , log_prefix); -openvpn_snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name); +snprintf (log_prefix,sizeof (log_prefix),"Incoming %s" , name);init_key_ctx (&ctx->decrypt, &key2->keys[kds.in_key], kt,OPENVPN_OP_DECRYPT , log_prefix);
src/openvpn/crypto_mbedtls.c +5 -5
@@ -128,7 +128,7 @@ {char prefix[256 ]; -if (!openvpn_snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) +if (!snprintf (prefix,sizeof (prefix),"%s:%d" , func, line)) {return mbed_log_err (flags, errval, func); }
@@ -239,11 +239,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----\n" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----\n" , name)) {return false; }
@@ -278,11 +278,11 @@char header[1000 +1 ] = {0 };char footer[1000 +1 ] = {0 }; -if (!openvpn_snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) +if (!snprintf (header,sizeof (header),"-----BEGIN %s-----" , name)) {return false; } -if (!openvpn_snprintf (footer,sizeof (footer),"-----END %s-----" , name)) +if (!snprintf (footer,sizeof (footer),"-----END %s-----" , name)) {return false; }
src/openvpn/dns.c +2 -2
@@ -349,11 +349,11 @@if (j <0 ) { - name_ok =openvpn_snprintf (name,sizeof (name), format, i); + name_ok =snprintf (name,sizeof (name), format, i); }else { - name_ok =openvpn_snprintf (name,sizeof (name), format, i, j); + name_ok =snprintf (name,sizeof (name), format, i, j); }if (!name_ok)
src/openvpn/env_set.c +4 -4
@@ -259,7 +259,7 @@ setenv_counter(struct env_set *es, const char *name, counter_type value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf), counter_format, value); +snprintf (buf,sizeof (buf), counter_format, value);setenv_str (es, name, buf); }
@@ -267,7 +267,7 @@ setenv_int(struct env_set *es, const char *name, int value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%d" , value); +snprintf (buf,sizeof (buf),"%d" , value);setenv_str (es, name, buf); }
@@ -275,7 +275,7 @@ setenv_long_long(struct env_set *es, const char *name, long long value) { char buf[64]; -openvpn_snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value); +snprintf (buf,sizeof (buf),"%" PRIi64, (int64_t )value);setenv_str (es, name, buf); }
@@ -310,7 +310,7 @@strcpy (tmpname, name);while (NULL !=env_set_get (es, tmpname) && counter <1000 ) { -ASSERT (openvpn_snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); +ASSERT (snprintf (tmpname, tmpname_len,"%s_%u" , name, counter)); counter++; }if (counter <1000 )
src/openvpn/error.c +7 -7
@@ -274,14 +274,14 @@if ((flags &M_ERRNO ) && e) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , - m1,openvpn_strerror (e, crt_error, &gc), e); +snprintf (m2,ERR_BUF_SIZE ,"%s: %s (errno=%d)" , + m1,openvpn_strerror (e, crt_error, &gc), e);SWAP ; }if (flags &M_OPTERR ) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1); +snprintf (m2,ERR_BUF_SIZE ,"Options error: %s" , m1);SWAP ; }
@@ -321,10 +321,10 @@const struct virtual_output *vo =msg_get_virtual_output ();if (vo) { -openvpn_snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , - prefix, - prefix_sep, - m1); +snprintf (m2,ERR_BUF_SIZE ,"%s%s%s" , + prefix, + prefix_sep, + m1);virtual_output_print (vo, flags, m2); } }
src/openvpn/init.c +1 -1
@@ -359,7 +359,7 @@char *out =malloc (len);check_malloc_return (out); -openvpn_snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); +snprintf (out, len,"%s,%s,%s,%s" , ce->remote, ce->remote_port, proto, status); *remote = out; }else
src/openvpn/manage.c +4 -4
@@ -515,8 +515,8 @@char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); -openvpn_snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes); +snprintf (in,sizeof (in), counter_format, man->persist.bytes_in + dco_read_bytes); +snprintf (out,sizeof (out), counter_format, man->persist.bytes_out + dco_write_bytes);msg (M_CLIENT ,">BYTECOUNT:%s,%s" , in, out); }
@@ -528,8 +528,8 @@char in[32 ];char out[32 ];/* do in a roundabout way to work around possible mingw or mingw-glibc bug */ -openvpn_snprintf (in,sizeof (in), counter_format, *bytes_in_total); -openvpn_snprintf (out,sizeof (out), counter_format, *bytes_out_total); +snprintf (in,sizeof (in), counter_format, *bytes_in_total); +snprintf (out,sizeof (out), counter_format, *bytes_out_total);msg (M_CLIENT ,">BYTECOUNT_CLI:%lu,%s,%s" , mdac->cid, in, out); mdac->bytecount_last_update = now; }
src/openvpn/options.c +4 -4
@@ -1427,7 +1427,7 @@for (int i =1 ; i <= opt_max; ++i) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , i); +snprintf (name,sizeof (name),"foreign_option_%d" , i);const char *env_str =env_set_get (es, name);const char *value =strchr (env_str,'=' ) +1 ;
@@ -1482,7 +1482,7 @@while (o->foreign_option_index < opt_max) {char name[32 ]; -openvpn_snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--); +snprintf (name,sizeof (name),"foreign_option_%d" , opt_max--);setenv_del (es, name); } }
@@ -5674,8 +5674,8 @@#ifndef ENABLE_SMALL {char script_name[100 ]; -openvpn_snprintf (script_name,sizeof (script_name), -"--%s script" , type); +snprintf (script_name,sizeof (script_name), +"--%s script" , type);if (check_cmd_access (*script, script_name, (in_chroot ? options->chroot_dir :NULL ))) {
src/openvpn/pkcs11.c +3 -3
@@ -201,7 +201,7 @@CLEAR (token_resp); token_resp.defined = false; token_resp.nocache = true; - openvpn_snprintf( + snprintf( token_resp.username, sizeof(token_resp.username), "Please insert %s token",
@@ -245,7 +245,7 @@ASSERT (token!=NULL ); -openvpn_snprintf (prompt,sizeof (prompt),"%s token" , token->label); +snprintf (prompt,sizeof (prompt),"%s token" , token->label); token_pass.defined = false; token_pass.nocache = true;
@@ -719,7 +719,7 @@ id_resp.defined = false; id_resp.nocache = true; -openvpn_snprintf ( +snprintf ( id_resp.username,sizeof (id_resp.username), "Please specify PKCS#11 id to use"
src/openvpn/platform.c +3 -3
@@ -564,9 +564,9 @@ { ++attempts; -if (!openvpn_snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, - prefix, (unsigned long )get_random (), - (unsigned long )get_random ())) +if (!snprintf (fname,sizeof (fname), fname_fmt, max_prefix_len, + prefix, (unsigned long )get_random (), + (unsigned long )get_random ())) {msg (M_WARN ,"ERROR: temporary filename too long" );return NULL ;
src/openvpn/plugin.c +2 -2
@@ -260,7 +260,7 @@ {char full[PATH_MAX ]; -openvpn_snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); +snprintf (full,sizeof (full),"%s/%s" ,PLUGIN_LIBDIR , p->so_pathname); p->handle =dlopen (full,RTLD_NOW ); } else
@@ -409,7 +409,7 @@gc_init (&gc); msg_fmt =gc_malloc (ERR_BUF_SIZE , false, &gc); -openvpn_snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format); +snprintf (msg_fmt,ERR_BUF_SIZE ,"PLUGIN %s: %s" , name, format);x_msg_va (msg_flags, msg_fmt, arglist);gc_free (&gc);
src/openvpn/pool.c +1 -1
@@ -766,7 +766,7 @@ifconfig_pool_handle h;in_addr_t local, remote;char buf[256 ]; -openvpn_snprintf (buf,sizeof (buf),"common-name-%d" , i); +snprintf (buf,sizeof (buf),"common-name-%d" , i);#ifdef DUP_CN cn =NULL ;#else
src/openvpn/proxy.c +44 -43
185 lines not on this page · raw message
src/openvpn/ps.c +1 -1
@@ -354,7 +354,7 @@ fnlen =strlen (journal_dir) +strlen (t) +2 ; jfn = (char *)malloc (fnlen);check_malloc_return (jfn); -openvpn_snprintf (jfn, fnlen,"%s/%s" , journal_dir, t); +snprintf (jfn, fnlen,"%s/%s" , journal_dir, t);dmsg (D_PS_PROXY_DEBUG ,"PORT SHARE PROXY: client origin %s -> %s" , jfn, f); fd =platform_open (jfn,O_CREAT |O_TRUNC |O_WRONLY ,S_IRUSR |S_IWUSR |S_IRGRP );if (fd !=-1 )
src/openvpn/route.c +3 -3
@@ -1621,11 +1621,11 @@if (rgi) { -openvpn_snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); +snprintf (out,sizeof (out),"%s %s %s dev %s" , network, netmask, gateway, rgi->iface); }else { -openvpn_snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); +snprintf (out,sizeof (out),"%s %s %s" , network, netmask, gateway); }bool ret =management_android_control (management,"ROUTE" , out); status = ret ?RTA_SUCCESS :RTA_ERROR ;
@@ -2000,7 +2000,7 @@#elif defined (TARGET_ANDROID )char out[64 ]; -openvpn_snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); +snprintf (out,sizeof (out),"%s/%d %s" , network, r6->netbits, device); status =management_android_control (management,"ROUTE6" , out);
src/openvpn/run_command.h +2 -2
@@ -66,8 +66,8 @@ {char msg[256 ]; -openvpn_snprintf (msg,sizeof (msg), -"WARNING: Failed running command (%s)" , hook); +snprintf (msg,sizeof (msg), +"WARNING: Failed running command (%s)" , hook);return openvpn_execve_check (a, es, flags |S_SCRIPT , msg); }
src/openvpn/socket.c +6 -6
@@ -2983,11 +2983,11 @@case AF_INET :if (flags &SA_IP_PORT ) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix); }inet_ntop (AF_INET , &addr->addr.in4.sin_addr, buf,sizeof (buf));
@@ -2995,7 +2995,7 @@if ((flags &SA_IP_PORT ) && addr->addr.in4.sin_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in4.sin_port)); }break ;
@@ -3006,19 +3006,19 @@struct in_addr ia;memcpy (&ia.s_addr, &addr->addr.in6.sin6_addr.s6_addr[12 ],sizeof (ia.s_addr)); -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip" , name_prefix);inet_ntop (AF_INET , &ia, buf,sizeof (buf)); }else { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix);inet_ntop (AF_INET6 , &addr->addr.in6.sin6_addr, buf,sizeof (buf)); }setenv_str (es, name_buf, buf);if ((flags &SA_IP_PORT ) && addr->addr.in6.sin6_port) { -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix); +snprintf (name_buf,sizeof (name_buf),"%s_port" , name_prefix);setenv_int (es, name_buf,ntohs (addr->addr.in6.sin6_port)); }break ;
src/openvpn/socks.c +4 -3
@@ -109,9 +109,10 @@ "Authentication not possible."); goto cleanup; } -int sret =openvpn_snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , - (int )strlen (creds.username), creds.username, - (int )strlen (creds.password), creds.password); + +int sret =snprintf (to_send,sizeof (to_send),"\x01%c%s%c%s" , + (int )strlen (creds.username), creds.username, + (int )strlen (creds.password), creds.password);ASSERT (sret <=sizeof (to_send)); size =send (sd, to_send,strlen (to_send),MSG_NOSIGNAL );
src/openvpn/ssl_mbedtls.c +6 -6
@@ -1531,16 +1531,16 @@char s2[256 ]; s1[0 ] = s2[0 ] =0 ; -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s" , - prefix, -mbedtls_ssl_get_version (ks_ssl->ctx), -mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s" , + prefix, +mbedtls_ssl_get_version (ks_ssl->ctx), +mbedtls_ssl_get_ciphersuite (ks_ssl->ctx)); cert =mbedtls_ssl_get_peer_cert (ks_ssl->ctx);if (cert !=NULL ) { -openvpn_snprintf (s2,sizeof (s2),", %u bit key" , - (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); +snprintf (s2,sizeof (s2),", %u bit key" , + (unsigned int )mbedtls_pk_get_bitlen (&cert->pk)); }msg (D_HANDSHAKE ,"%s%s" , s1, s2);
src/openvpn/ssl_ncp.c +2 -2
@@ -198,8 +198,8 @@size_t newlen =strlen (o->ncp_ciphers) +1 +strlen (ciphername) +1 ;char *ncp_ciphers =gc_malloc (newlen, false, &o->gc); -ASSERT (openvpn_snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, - ciphername)); +ASSERT (snprintf (ncp_ciphers, newlen,"%s:%s" , o->ncp_ciphers, + ciphername)); o->ncp_ciphers = ncp_ciphers; }
src/openvpn/ssl_openssl.c +16 -16
@@ -1774,7 +1774,7 @@if (!biofp) {char fn[256 ]; -openvpn_snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); +snprintf (fn,sizeof (fn),"bio/%d-%d.log" , pid, biofp_toggle); biofp =fopen (fn,"w" );ASSERT (biofp); biofp_last_open =time (NULL );
@@ -2116,8 +2116,8 @@#endif /* if OPENSSL_VERSION_NUMBER < 0x30000000L */ } -openvpn_snprintf (buf, buflen,"%d bits %s%s" , -EVP_PKEY_bits (pkey), type, curve); +snprintf (buf, buflen,"%d bits %s%s" , +EVP_PKEY_bits (pkey), type, curve); }/**
@@ -2137,12 +2137,12 @@int signature_nid =X509_get_signature_nid (cert);if (signature_nid !=0 ) { -openvpn_snprintf (sig,sizeof (sig),", signature: %s" , -OBJ_nid2sn (signature_nid)); +snprintf (sig,sizeof (sig),", signature: %s" , +OBJ_nid2sn (signature_nid)); } -openvpn_snprintf (buf, buflen,", peer certificate: %s%s" , - pkeybuf, sig); +snprintf (buf, buflen,", peer certificate: %s%s" , + pkeybuf, sig);EVP_PKEY_free (pkey); }
@@ -2160,8 +2160,8 @@char pkeybuf[128 ] = {0 };print_pkey_details (pkey, pkeybuf,sizeof (pkeybuf)); -openvpn_snprintf (buf, buflen,", peer temporary key: %s" , - pkeybuf); +snprintf (buf, buflen,", peer temporary key: %s" , + pkeybuf);EVP_PKEY_free (pkey); }
@@ -2238,8 +2238,8 @@return ; } -openvpn_snprintf (buf, buflen,", peer signing digest/type: %s %s" , - peer_sig, peer_sig_type); +snprintf (buf, buflen,", peer signing digest/type: %s %s" , + peer_sig, peer_sig_type); }
@@ -2262,11 +2262,11 @@ s1[0 ] = s2[0 ] = s3[0 ] = s4[0 ] =0 ; ciph =SSL_get_current_cipher (ks_ssl->ssl); -openvpn_snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , - prefix, -SSL_get_version (ks_ssl->ssl), -SSL_CIPHER_get_version (ciph), -SSL_CIPHER_get_name (ciph)); +snprintf (s1,sizeof (s1),"%s %s, cipher %s %s" , + prefix, +SSL_get_version (ks_ssl->ssl), +SSL_CIPHER_get_version (ciph), +SSL_CIPHER_get_name (ciph));X509 *cert =SSL_get_peer_certificate (ks_ssl->ssl);if (cert)
src/openvpn/ssl_verify.c +11 -11
@@ -421,12 +421,12 @@ }/* export subject name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_id_%d" , cert_depth);setenv_str (es, envname, subject);#if 0 /* export common name string as environmental variable */ -openvpn_snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_common_name_%d" , cert_depth);setenv_str (es, envname, common_name);#endif
@@ -435,24 +435,24 @@struct buffer sha1 =x509_get_sha1_fingerprint (peer_cert, &gc);struct buffer sha256 =x509_get_sha256_fingerprint (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_%d" , cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha1),BLEN (&sha1),0 ,1 ,":" , &gc)); -openvpn_snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , - cert_depth); +snprintf (envname,sizeof (envname),"tls_digest_sha256_%d" , + cert_depth);setenv_str (es, envname,format_hex_ex (BPTR (&sha256),BLEN (&sha256),0 ,1 ,":" , &gc)); }/* export serial number as environmental variable */ serial =backend_x509_get_serial (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth);setenv_str (es, envname, serial);/* export serial number in hex as environmental variable */ serial =backend_x509_get_serial_hex (peer_cert, &gc); -openvpn_snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth); +snprintf (envname,sizeof (envname),"tls_serial_hex_%d" , cert_depth);setenv_str (es, envname, serial);gc_free (&gc);
@@ -569,7 +569,7 @@ goto cleanup; } -if (!openvpn_snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) +if (!snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,PATH_SEPARATOR , serial)) {msg (D_HANDSHAKE ,"VERIFY CRL: filename overflow" ); goto cleanup;
@@ -938,9 +938,9 @@if (!check_auth_pending_method (multi->peer_info, pending_method)) {char buf[128 ]; -openvpn_snprintf (buf,sizeof (buf), -"Authentication failed, required pending auth " -"method '%s' not supported" , pending_method); +snprintf (buf,sizeof (buf), +"Authentication failed, required pending auth " +"method '%s' not supported" , pending_method);auth_set_client_reason (multi, buf);msg (M_INFO ,"Client does not supported auth pending method " "'%s'" , pending_method);
src/openvpn/ssl_verify_mbedtls.c +7 -7
@@ -86,8 +86,8 @@char *serial =backend_x509_get_serial (cert, &gc); ret =mbedtls_x509_crt_verify_info (errstr,sizeof (errstr)-1 ,"" , *flags); -if (ret <=0 && !openvpn_snprintf (errstr,sizeof (errstr), -"Could not retrieve error string, flags=%" PRIx32, *flags)) +if (ret <=0 && !snprintf (errstr,sizeof (errstr), +"Could not retrieve error string, flags=%" PRIx32, *flags)) { errstr[0 ] ='\0' ; }
@@ -307,7 +307,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -431,13 +431,13 @@if (0 ==mbedtls_oid_get_attr_short_name (&name->oid, &shortname) ) { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , - cert_depth, shortname); +snprintf (name_expand,sizeof (name_expand),"X509_%d_%s" , + cert_depth, shortname); }else { -openvpn_snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , - cert_depth); +snprintf (name_expand,sizeof (name_expand),"X509_%d_\?\?" , + cert_depth); }for (i =0 ; i < name->val.len; i++)
src/openvpn/ssl_verify_openssl.c +4 -4
@@ -279,7 +279,7 @@gc_free (&gc);return FAILURE ; } -openvpn_snprintf (common_name, cn_len,"0x%s" , serial); +snprintf (common_name, cn_len,"0x%s" , serial);gc_free (&gc); }else
@@ -454,7 +454,7 @@ name_expand_size =64 +strlen (name); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , depth, name);setenv_str (es, name_expand, value);free (name_expand); }
@@ -597,8 +597,8 @@ name_expand_size =64 +strlen (objbuf); name_expand = (char *)malloc (name_expand_size);check_malloc_return (name_expand); -openvpn_snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, - objbuf); +snprintf (name_expand, name_expand_size,"X509_%d_%s" , cert_depth, + objbuf);string_mod (name_expand,CC_PRINT ,CC_CRLF ,'_' );string_mod ((char *)buf,CC_PRINT ,CC_CRLF ,'_' );setenv_str_incr (es, name_expand, (char *)buf);
src/openvpn/tls_crypt.c +2 -2
@@ -574,8 +574,8 @@ }char metadata_type_str[4 ] = {0 };/* Max value: 255 */ -openvpn_snprintf (metadata_type_str,sizeof (metadata_type_str), -"%i" , (uint8_t ) metadata_type); +snprintf (metadata_type_str,sizeof (metadata_type_str), +"%i" , (uint8_t ) metadata_type);struct env_set *es =env_set_create (NULL );setenv_str (es,"script_type" ,"tls-crypt-v2-verify" );setenv_str (es,"metadata_type" , metadata_type_str);
src/openvpn/tun.c +34 -34
164 lines not on this page · raw message
src/openvpn/win32.c +5 -20
@@ -885,8 +885,8 @@char force_path[256 ];char *sysroot =get_win_sys_path (); -if (!openvpn_snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , - sysroot, sysroot, sysroot)) +if (!snprintf (force_path,sizeof (force_path),"PATH=%s\\System32;%s;%s\\System32\\Wbem" , + sysroot, sysroot, sysroot)) {msg (M_WARN ,"env_block: default path truncated to %s" , force_path); }
@@ -1483,26 +1483,11 @@ }bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...) -{ -va_list arglist; -int len =-1 ; -if (size >0 ) - { -va_start (arglist, format); - len =vswprintf (str, size, format, arglist); -va_end (arglist); - str[size -1 ] =L'\0' ; - } -return (len >=0 && len < size); -} - -bool get_openvpn_reg_value (const WCHAR *key,WCHAR *value,DWORD size) {WCHAR reg_path[256 ];HKEY hkey; -openvpn_swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME ); +swprintf (reg_path,_countof (reg_path),L"SOFTWARE\\" PACKAGE_NAME );LONG status =RegOpenKeyExW (HKEY_LOCAL_MACHINE , reg_path,0 ,KEY_READ , &hkey);if (status !=ERROR_SUCCESS )
@@ -1528,7 +1513,7 @@/* if we cannot find installation path from the registry, * use Windows directory as a fallback */ -openvpn_swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); +swprintf (install_path,_countof (install_path),L"%ls" , ssl_fallback_dir); }if ((install_path[wcslen (install_path) -1 ]) ==L'\\' )
@@ -1553,7 +1538,7 @@if (size ==0 ) {WCHAR val[MAX_PATH ] = {0 }; -openvpn_swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value); +swprintf (val,_countof (val),L"%ls\\ssl\\%ls" , install_path, ossl_env[i].value);_wputenv_s (ossl_env[i].name, val); } }
src/openvpn/win32.h +0 -8
@@ -319,14 +319,6 @@int openvpn_execve (const struct argv *a,const struct env_set *es,const unsigned int flags); -/* -* openvpn_swprintf() is currently only used by Windows code paths -* and when enabled for all platforms it will currently break older -* OpenBSD versions lacking vswprintf(3) support in their libc. -*/ -bool -openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -/* Sleep that can be interrupted by signals and exit event */ void win32_sleep (const int n);
src/openvpn/xkey_helper.c +5 -5
@@ -205,7 +205,7 @@ }else { -openvpn_snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"ECDSA,hashalg=%s" , alg.mdname); } }else if (!strcmp (alg.keytype,"ED448" ) || !strcmp (alg.keytype,"ED25519" ))
@@ -229,8 +229,8 @@/* For undigested message, add hashalg=digest parameter */ else { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , -"RSA_PKCS1_PADDING" , alg.mdname); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s" , +"RSA_PKCS1_PADDING" , alg.mdname); } } else if (!strcmp(alg.padmode, "none") && (flags & MF_EXTERNAL_KEY_NOPADDING)
@@ -240,8 +240,8 @@ }else if (!strcmp (alg.padmode,"pss" ) && (flags &MF_EXTERNAL_KEY_PSSPAD )) { -openvpn_snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , -"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); +snprintf (alg_str,sizeof (alg_str),"%s,hashalg=%s,saltlen=%s" , +"RSA_PKCS1_PSS_PADDING" , alg.mdname, alg.saltlen); }else {
src/openvpnserv/common.c +11 -41
102 lines not on this page · raw message
src/openvpnserv/interactive.c +30 -27
162 lines not on this page · raw message
src/openvpnserv/service.h +0 -6
@@ -81,12 +81,6 @@ VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv); -BOOL openvpn_vsntprintf (LPTSTR str,size_t size,LPCTSTR format,va_list arglist); - -BOOL openvpn_sntprintf (LPTSTR str,size_t size,LPCTSTR format, ...); - -BOOL openvpn_swprintf (wchar_t *const str,const size_t size,const wchar_t *const format, ...); -DWORD GetOpenvpnSettings (settings_t *s);BOOL ReportStatusToSCMgr (SERVICE_STATUS_HANDLE service,SERVICE_STATUS *status);
src/openvpnserv/validate.c +1 -1
@@ -68,7 +68,7 @@/* convert fname to full path */ if (PathIsRelativeW (fname) ) { -openvpn_swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); +swprintf (tmp,_countof (tmp),L"%ls\\%ls" , workdir, fname); config_file = tmp; }else
tests/unit_tests/openvpn/test_buffer.c +51 -0
63 lines not on this page · raw message
tests/unit_tests/openvpn/test_cryptoapi.c +5 -5
@@ -271,7 +271,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); ctx =find_certificate_in_store (select_string, user_store);if (ctx) {
@@ -304,7 +304,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); +snprintf (select_string,sizeof (select_string),"SUBJ:%s" , c->cname); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the common name. But the returned cert may not exactly match
@@ -337,7 +337,7 @@for (struct test_cert *c = certs; c->cert; c++) { -openvpn_snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); +snprintf (select_string,sizeof (select_string),"ISSUER:%s" , c->issuer); ctx =find_certificate_in_store (select_string, user_store);/* In this case we expect a successful return as there is at least one valid * cert that matches the issuer. But the returned cert may not exactly match
@@ -411,7 +411,7 @@ {continue ; } -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (Load_CryptoAPI_certificate (select_string, &x509, &privkey) !=1 ) {fail_msg ("Load_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
@@ -446,7 +446,7 @@SSL_CTX *ssl_ctx =SSL_CTX_new_ex (tls_libctx,NULL ,SSLv23_client_method ());assert_non_null (ssl_ctx); -openvpn_snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash); +snprintf (select_string,sizeof (select_string),"THUMB:%s" , c->hash);if (!SSL_CTX_use_CryptoAPI_certificate (ssl_ctx, select_string)) {fail_msg ("SSL_CTX_use_CryptoAPI_certificate failed: <%s>" , c->friendly_name);
tests/unit_tests/openvpn/test_pkcs11.c +3 -3
@@ -161,7 +161,7 @@ }else if (flags &GET_USER_PASS_PASSWORD_ONLY ) { -openvpn_snprintf (up->password,sizeof (up->password),"%s" ,PIN ); +snprintf (up->password,sizeof (up->password),"%s" ,PIN ); }else {
@@ -204,8 +204,8 @@ {fail_msg ("make tmpfile using template <%s> failed (error = %d)" , softhsm2_conf_path, errno); } -openvpn_snprintf (config,sizeof (config),"directories.tokendir=%s/" , - softhsm2_tokens_path); +snprintf (config,sizeof (config),"directories.tokendir=%s/" , + softhsm2_tokens_path);assert_int_equal (write (fd, config,strlen (config)),strlen (config));close (fd);
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac
Gerrit-Change-Number: 547
Gerrit-PatchSet: 6
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged